pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

  • <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="uakaw6i" 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="0kmm2cm" 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="0eusyoc" 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. 主站蜘蛛池模板: 衬氟止回阀_衬氟闸阀_衬氟三通球阀_衬四氟阀门_衬氟阀门厂-浙江利尔多阀门有限公司 | 购买舔盐、舔砖、矿物质盐压块机,鱼饵、鱼饲料压块机--请到杜甫机械 | 无锡网站建设_小程序制作_网站设计公司_无锡网络公司_网站制作 | 赛尔特智能移动阳光房-阳光房厂家-赛尔特建筑科技(广东)有限公司 | 消防泵-XBD单级卧式/立式消防泵-上海塑泉泵阀(集团)有限公司 | 流程管理|流程管理软件|企业流程管理|微宏科技-AlphaFlow_流程管理系统软件服务商 | 无硅导热垫片-碳纤维导热垫片-导热相变材料厂家-东莞市盛元新材料科技有限公司 | 政府回应:200块在义乌小巷能买到爱情吗?——揭秘打工族省钱约会的生存智慧 | 液压中心架,数控中心架,自定心中心架-烟台恒阳机电设计有限公司 行星搅拌机,双行星搅拌机,动力混合机,无锡米克斯行星搅拌机生产厂家 | 北京发电车出租-发电机租赁公司-柴油发电机厂家 - 北京明旺盛安机电设备有限公司 | 深圳市索富通实业有限公司-可燃气体报警器 | 可燃气体探测器 | 气体检测仪 | 鲁尔圆锥接头多功能测试仪-留置针测试仪-上海威夏环保科技有限公司 | 安平县鑫川金属丝网制品有限公司,防风抑尘网,单峰防风抑尘,不锈钢防风抑尘网,铝板防风抑尘网,镀铝锌防风抑尘网 | 防水套管-柔性防水套管-刚性防水套管-上海执品管件有限公司 | 时代北利离心机,实验室离心机,医用离心机,低速离心机DT5-2,美国SKC采样泵-上海京工实业有限公司 工业电炉,台车式电炉_厂家-淄博申华工业电炉有限公司 | 手术室净化厂家_成都实验室装修公司_无尘车间施工单位_洁净室工程建设团队-四川华锐16年行业经验 | 托利多电子平台秤-高精度接线盒-托利多高精度电子秤|百科 | 液压油缸生产厂家-山东液压站-济南捷兴液压机电设备有限公司 | 菲希尔FISCHER测厚仪-铁素体检测仪-上海吉馨实业发展有限公司 | hdpe土工膜-防渗膜-复合土工膜-长丝土工布价格-厂家直销「恒阳新材料」-山东恒阳新材料有限公司 ETFE膜结构_PTFE膜结构_空间钢结构_膜结构_张拉膜_浙江萬豪空间结构集团有限公司 | 机械立体车库租赁_立体停车设备出租_智能停车场厂家_春华起重 | 粉末包装机,拆包机厂家,价格-上海强牛包装机械设备有限公司 | 石英陶瓷,石英坩埚,二氧化硅陶瓷-淄博百特高新材料有限公司 | 高通量组织研磨仪-多样品组织研磨仪-全自动组织研磨仪-研磨者科技(广州)有限公司 | 电车线(用于供电给电车的输电线路)-百科| 热缩管切管机-超声波切带机-织带切带机-无纺布切布机-深圳市宸兴业科技有限公司 | 影像测量仪_三坐标测量机_一键式二次元_全自动影像测量仪-广东妙机精密科技股份有限公司 | 高防护蠕动泵-多通道灌装系统-高防护蠕动泵-www.bjhuiyufluid.com慧宇伟业(北京)流体设备有限公司 | 昆明网络公司|云南网络公司|昆明网站建设公司|昆明网页设计|云南网站制作|新媒体运营公司|APP开发|小程序研发|尽在昆明奥远科技有限公司 | atcc网站,sigma试剂价格,肿瘤细胞现货,人结肠癌细胞株购买-南京科佰生物 | atcc网站,sigma试剂价格,肿瘤细胞现货,人结肠癌细胞株购买-南京科佰生物 | 三佳互联一站式网站建设服务|网站开发|网站设计|网站搭建服务商 赛默飞Thermo veritiproPCR仪|ProFlex3 x 32PCR系统|Countess3细胞计数仪|371|3111二氧化碳培养箱|Mirco17R|Mirco21R离心机|仟诺生物 | 私人别墅家庭影院系统_家庭影院音响_家庭影院装修设计公司-邦牛影音 | 低温柔性试验仪-土工布淤堵-沥青车辙试验仪-莱博特(天津)试验机有限公司 | 科研ELISA试剂盒,酶联免疫检测试剂盒,昆虫_植物ELISA酶免试剂盒-上海仁捷生物科技有限公司 | 镀锌方管,无缝方管,伸缩套管,方矩管_山东重鑫致胜金属制品有限公司 | 澳威全屋定制官网|极简衣柜十大品牌|衣柜加盟代理|全屋定制招商 百度爱采购运营研究社社群-店铺托管-爱采购代运营-良言多米网络公司 | 100国际学校招生 - 专业国际学校择校升学规划 | 电液推杆生产厂家|电动推杆|液压推杆-扬州唯升机械有限公司 | 家庭教育吧-在线家庭教育平台,专注青少年家庭教育 | 红酒招商加盟-葡萄酒加盟-进口红酒代理-青岛枞木酒业有限公司 |