久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

  • <legend id='PuZbR'><style id='PuZbR'><dir id='PuZbR'><q id='PuZbR'></q></dir></style></legend>
  • <small id='PuZbR'></small><noframes id='PuZbR'>

    <i id='PuZbR'><tr id='PuZbR'><dt id='PuZbR'><q id='PuZbR'><span id='PuZbR'><b id='PuZbR'><form id='PuZbR'><ins id='PuZbR'></ins><ul id='PuZbR'></ul><sub id='PuZbR'></sub></form><legend id='PuZbR'></legend><bdo id='PuZbR'><pre id='PuZbR'><center id='PuZbR'></center></pre></bdo></b><th id='PuZbR'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='PuZbR'><tfoot id='PuZbR'></tfoot><dl id='PuZbR'><fieldset id='PuZbR'></fieldset></dl></div>
      <tfoot id='PuZbR'></tfoot>
        <bdo id='PuZbR'></bdo><ul id='PuZbR'></ul>

      1. 設(shè)置選項“已選擇";來自動態(tài)創(chuàng)建選項的屬

        set option quot;selectedquot; attribute from dynamic created option(設(shè)置選項“已選擇;來自動態(tài)創(chuàng)建選項的屬性)
      2. <small id='GYktH'></small><noframes id='GYktH'>

            <bdo id='GYktH'></bdo><ul id='GYktH'></ul>
              <tbody id='GYktH'></tbody>
            <legend id='GYktH'><style id='GYktH'><dir id='GYktH'><q id='GYktH'></q></dir></style></legend>
                <tfoot id='GYktH'></tfoot>

              • <i id='GYktH'><tr id='GYktH'><dt id='GYktH'><q id='GYktH'><span id='GYktH'><b id='GYktH'><form id='GYktH'><ins id='GYktH'></ins><ul id='GYktH'></ul><sub id='GYktH'></sub></form><legend id='GYktH'></legend><bdo id='GYktH'><pre id='GYktH'><center id='GYktH'></center></pre></bdo></b><th id='GYktH'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='GYktH'><tfoot id='GYktH'></tfoot><dl id='GYktH'><fieldset id='GYktH'></fieldset></dl></div>

                  本文介紹了設(shè)置選項“已選擇";來自動態(tài)創(chuàng)建選項的屬性的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                  問題描述

                  我有一個使用 javascript 函數(shù)動態(tài)創(chuàng)建的選擇選項.選擇對象是

                  I have a dynamically created select option using a javascript function. the select object is

                  <select name="country" id="country">
                  </select>
                  

                  js函數(shù)執(zhí)行時,country"對象為

                  when the js function is executed, the "country" object is

                  <select name="country" id="country">
                      <option value="AF">Afghanistan</option>
                      <option value="AL">Albania</option>
                      ...
                      <option value="ID">Indonesia</option>
                      ...
                      <option value="ZW">Zimbabwe</option>
                  </select>
                  

                  并顯示印度尼西亞"作為默認(rèn)選擇選項.注意:該選項中沒有 selected="selected" 屬性.

                  and displaying "Indonesia" as default selected option. note : there is no selected="selected" attribute in that option.

                  然后我需要將 selected="selected" 屬性設(shè)置為印度尼西亞",我使用這個

                  then I need to set selected="selected" attribute to "Indonesia", and I use this

                  var country = document.getElementById("country");
                  country.options[country.options.selectedIndex].setAttribute("selected", "selected");
                  

                  使用firebug,我可以看到印度尼西亞"選項是這樣的

                  using firebug, I can see the "Indonesia" option is like this

                  <option value="ID" selected="selected">Indonesia</option>
                  

                  但它在 IE 中失敗(在 IE 8 中測試).

                  but it fails in IE (tested in IE 8).

                  然后我嘗試使用 jQuery

                  and then I have tried using jQuery

                  $( function() {
                      $("#country option:selected").attr("selected", "selected");
                  });
                  

                  在 FFX 和 IE 中都失敗了.

                  it fails both in FFX and IE.

                  我需要印度尼西亞"選項具有 selected="selected" 屬性,因此當(dāng)我單擊重置按鈕時,它將再次選擇印度尼西亞".

                  I need the "Indonesia" option to have selected="selected" attribute so when I click reset button, it will select "Indonesia" again.

                  更改 js 函數(shù)以動態(tài)創(chuàng)建國家/地區(qū)"選項不是一種選擇.該解決方案必須在 FFX 和 IE 中都有效.

                  changing the js function to dynamically create "country" options is not an option. the solution must work both in FFX and IE.

                  謝謝

                  推薦答案

                  好問題.您將需要修改 HTML 本身,而不是依賴 DOM 屬性.

                  Good question. You will need to modify the HTML itself rather than rely on DOM properties.

                  var opt = $("option[val=ID]"),
                      html = $("<div>").append(opt.clone()).html();
                  html = html.replace(/>/, ' selected="selected">');
                  opt.replaceWith(html);
                  

                  代碼抓取印度尼西亞的 option 元素,將其克隆并放入新的 div(不在文檔中)以檢索完整的 HTML 字符串:<option value="ID">Indonesia</選項>.

                  The code grabs the option element for Indonesia, clones it and puts it into a new div (not in the document) to retrieve the full HTML string: <option value="ID">Indonesia</option>.

                  然后它會進(jìn)行字符串替換以添加屬性 selected="selected" 作為字符串,然后用這個新選項替換原始選項.

                  It then does a string replace to add the attribute selected="selected" as a string, before replacing the original option with this new one.

                  我在 IE7 上測試過.在這里看到重置按鈕正常工作:http://jsfiddle.net/XmW49/

                  I tested it on IE7. See it with the reset button working properly here: http://jsfiddle.net/XmW49/

                  這篇關(guān)于設(shè)置選項“已選擇";來自動態(tài)創(chuàng)建選項的屬性的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

                  【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

                  相關(guān)文檔推薦

                  Use IScroll in Angular 2 / Typescript(在 Angular 2/Typescript 中使用 IScroll)
                  anime.js not working in Ionic 3 project(Anime.js 在 Ionic 3 項目中不起作用)
                  Ionic 3 - Update Observable with Asynchronous Data(Ionic 3 - 使用異步數(shù)據(jù)更新 Observable)
                  Angular 2: file not found on local .json file(Angular 2:在本地 .json 文件中找不到文件)
                  In Ionic 2, how do I create a custom directive that uses Ionic components?(在 Ionic 2 中,如何創(chuàng)建使用 Ionic 組件的自定義指令?)
                  Use ViewChild for dynamic elements - Angular 2 amp; ionic 2(將 ViewChild 用于動態(tài)元素 - Angular 2 amp;離子2)
                  <legend id='nlHpJ'><style id='nlHpJ'><dir id='nlHpJ'><q id='nlHpJ'></q></dir></style></legend>
                • <i id='nlHpJ'><tr id='nlHpJ'><dt id='nlHpJ'><q id='nlHpJ'><span id='nlHpJ'><b id='nlHpJ'><form id='nlHpJ'><ins id='nlHpJ'></ins><ul id='nlHpJ'></ul><sub id='nlHpJ'></sub></form><legend id='nlHpJ'></legend><bdo id='nlHpJ'><pre id='nlHpJ'><center id='nlHpJ'></center></pre></bdo></b><th id='nlHpJ'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='nlHpJ'><tfoot id='nlHpJ'></tfoot><dl id='nlHpJ'><fieldset id='nlHpJ'></fieldset></dl></div>
                    <bdo id='nlHpJ'></bdo><ul id='nlHpJ'></ul>
                    • <tfoot id='nlHpJ'></tfoot>

                      <small id='nlHpJ'></small><noframes id='nlHpJ'>

                          <tbody id='nlHpJ'></tbody>

                          1. 主站蜘蛛池模板: 亚洲一区视频在线 | www.99热.com| 亚洲高清av在线 | 亚洲第一福利网 | 颜色网站在线观看 | 亚洲一区二区av | 欧美亚洲激情 | 99国产精品久久久 | 亚洲第一色站 | 欧美一级久久 | 99色在线 | www.久久.com | 天天躁人人躁人人躁狂躁 | 中文字幕在线观 | 精一区二区 | 男人的天堂视频网站 | 午夜视频一区二区 | 国产精品成人国产乱一区 | 九九久久99 | 米奇狠狠鲁 | 成人片免费看 | 日批免费在线观看 | 日韩视频在线免费观看 | 日韩成人精品一区 | 久久国产婷婷国产香蕉 | 精品国产乱码久久久久久中文 | 欧美1区 | 国产在线精品一区二区三区 | 国产精品a一区二区三区网址 | 国产伦一区二区三区 | 中文字幕亚洲一区二区三区 | 免费人成激情视频在线观看冫 | 一级片毛片| 天天操天天摸天天爽 | 九九亚洲 | 欧美日韩中文在线观看 | 国产一级免费视频 | 成人久久久 | 久久青青 | 国产午夜精品一区二区三区嫩草 | 日韩精品一区二区三区中文字幕 |