久久久久久久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. 設置選項“已選擇";來自動態創建選項的屬

        set option quot;selectedquot; attribute from dynamic created option(設置選項“已選擇;來自動態創建選項的屬性)
      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>

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

                  問題描述

                  我有一個使用 javascript 函數動態創建的選擇選項.選擇對象是

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

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

                  js函數執行時,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>
                  

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

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

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

                  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" 屬性,因此當我單擊重置按鈕時,它將再次選擇印度尼西亞".

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

                  更改 js 函數以動態創建國家/地區"選項不是一種選擇.該解決方案必須在 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>.

                  然后它會進行字符串替換以添加屬性 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/

                  這篇關于設置選項“已選擇";來自動態創建選項的屬性的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

                  相關文檔推薦

                  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 - 使用異步數據更新 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 中,如何創建使用 Ionic 組件的自定義指令?)
                  Use ViewChild for dynamic elements - Angular 2 amp; ionic 2(將 ViewChild 用于動態元素 - 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. 主站蜘蛛池模板: 亚洲国产一区视频 | 99精品久久久| 综合九九 | 一级做a爰片性色毛片 | 鲁视频| 日本成人一区二区 | 免费av手机在线观看 | www.9191| 国产99久久久国产精品 | 五月免费视频 | 国产1区 | 国产性色视频 | 精品国产一区二区三区免费 | 日本黄色免费大片 | 欧美色综合网 | 色视频网站 | 精品一二| 日韩成人在线网址 | 精品视频在线播放 | 日一区二区 | 久久69精品久久久久久久电影好 | 日韩av免费看 | 久久精品性视频 | 国产成人精品区一区二区不卡 | 日韩一区二区三区视频 | 国产1区2区 | 成人中文字幕在线 | 国产专区视频 | 国产综合久久 | 欧美国产精品 | 国产中文视频 | 国产99久久久国产精品 | 久久精品国产99国产精品 | 狠狠艹| 2019天天干夜夜操 | 免费一区二区三区在线视频 | 免费久久99精品国产婷婷六月 | 搞黄网站在线观看 | 欧美网站一区 | 日韩第一区 | 久久精品成人 |