久久久久久久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è)置選項(xiàng)“已選擇";來自動態(tài)創(chuàng)建選項(xiàng)的屬

        set option quot;selectedquot; attribute from dynamic created option(設(shè)置選項(xiàng)“已選擇;來自動態(tài)創(chuàng)建選項(xià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è)置選項(xiàng)“已選擇";來自動態(tài)創(chuàng)建選項(xiàng)的屬性的處理方法,對大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                  問題描述

                  我有一個(gè)使用 javascript 函數(shù)動態(tài)創(chuàng)建的選擇選項(xià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í)行時(shí),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)選擇選項(xiàng).注意:該選項(xiàng)中沒有 selected="selected" 屬性.

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

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

                  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,我可以看到印度尼西亞"選項(xiàng)是這樣的

                  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.

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

                  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ū)"選項(xiàng)不是一種選擇.該解決方案必須在 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</選項(xiàng)>.

                  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" 作為字符串,然后用這個(gè)新選項(xiàng)替換原始選項(xiàng).

                  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è)置選項(xiàng)“已選擇";來自動態(tài)創(chuàng)建選項(xià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 項(xiàng)目中不起作用)
                  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. 主站蜘蛛池模板: 亚洲色图网址 | 日本在线黄色 | 激情久久久久 | 狠狠操狠狠操 | 精品亚洲一区二区三区四区五区高 | 亚洲综合三区 | 国产精品伦理一区二区三区 | 亚洲视频免费播放 | 日韩在线免费播放 | 91久久久久久久久久久 | 亚洲 欧美 日韩 在线 | 在线欧美日韩 | 天天操天天舔 | 日韩成人在线播放 | 久久精品无码一区二区三区 | 性高湖久久久久久久久 | 精品久久久久久久久久久下田 | 99re视频在线观看 | 日本aⅴ中文字幕 | 精品视频在线播放 | 久久精品综合 | 午夜视频在线免费观看 | 一区二区三区四区免费观看 | 精品国产视频 | 国产欧美一区二区三区久久手机版 | 久久国产精品免费视频 | 日本三级在线视频 | 亚洲视频一区在线观看 | 天天爽网站 | 亚洲综合大片69999 | 精品国产免费人成在线观看 | 精品国产一区久久 | 中文字幕在线看第二 | 91精品国产一区二区 | 中文字幕在线免费观看 | 国产精品视频网 | 国产视频中文字幕在线观看 | 精品一区二区视频 | 91精品国产综合久久婷婷香蕉 | 国产乱码精品一区二区三区av | 免费视频二区 |