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. 主站蜘蛛池模板: HYDAC过滤器,HYDAC滤芯,现货ATOS油泵,ATOS比例阀-东莞市广联自动化科技有限公司 | 电镀标牌_电铸标牌_金属标贴_不锈钢标牌厂家_深圳市宝利丰精密科技有限公司 | 深圳网站建设-高端企业网站开发-定制网页设计制作公司 | 不锈钢法兰-碳钢法兰-法兰盘生产加工厂家-[鼎捷峰]-不锈钢法兰-碳钢法兰-法兰盘生产加工厂家-[鼎捷峰] | 大型冰雕-景区冰雕展制作公司,3D创意设计源头厂家-[赛北冰雕] | 臭氧实验装置_实验室臭氧发生器-北京同林臭氧装置网 | 地埋式垃圾站厂家【佳星环保】小区压缩垃圾中转站转运站 | 上海赞永| 塑料检查井_双扣聚氯乙烯增强管_双壁波纹管-河南中盈塑料制品有限公司 | 成都竞价托管_抖音代运营_网站建设_成都SEM外包-成都智网创联网络科技有限公司 | 带锯机|木工带锯机圆木推台锯|跑车带锯机|河北茂业机械制造有限公司| | 博博会2021_中国博物馆及相关产品与技术博览会【博博会】 | 泰国专线_泰国物流专线_广州到泰国物流公司-泰廊曼国际 | 不锈钢发酵罐_水果酒发酵罐_谷物发酵罐_山东誉诚不锈钢制品有限公司 | 高压无油空压机_无油水润滑空压机_水润滑无油螺杆空压机_无油空压机厂家-科普柯超滤(广东)节能科技有限公司 | 乐考网-银行从业_基金从业资格考试_初级/中级会计报名时间_中级经济师 | 手持式3d激光扫描仪-便携式三维立体扫描仪-北京福禄克斯 | 紫外荧光硫分析仪-硫含量分析仪-红外光度测定仪-泰州美旭仪器 | 植筋胶-粘钢胶-碳纤维布-碳纤维板-环氧砂浆-加固材料生产厂家-上海巧力建筑科技有限公司 | 自动部分收集器,进口无油隔膜真空泵,SPME固相微萃取头-上海楚定分析仪器有限公司 | 建筑资质代办-建筑企业资质代办机构-建筑资质代办公司 | 美缝剂_美缝剂厂家_美缝剂加盟-地老板高端瓷砖美缝剂 | 北京租车公司_汽车/客车/班车/大巴车租赁_商务会议/展会用车/旅游大巴出租_北京桐顺创业租车公司 | 衬氟止回阀_衬氟闸阀_衬氟三通球阀_衬四氟阀门_衬氟阀门厂-浙江利尔多阀门有限公司 | 台湾HIWIN上银直线模组|导轨滑块|TBI滚珠丝杆丝杠-深圳汉工 | 智能终端_RTU_dcm_北斗星空自动化科技 | 中山市派格家具有限公司【官网】 | 压力变送器-上海武锐自动化设备有限公司 | 合肥展厅设计-安徽展台设计-合肥展览公司-安徽奥美展览工程有限公司 | 澳门精准正版免费大全,2025新澳门全年免费,新澳天天开奖免费资料大全最新,新澳2025今晚开奖资料,新澳马今天最快最新图库-首页-东莞市傲马网络科技有限公司 | 富森高压水枪-柴油驱动-养殖场高压清洗机-山东龙腾环保科技有限公司 | 锂电混合机-新能源混合机-正极材料混料机-高镍,三元材料混料机-负极,包覆混合机-贝尔专业混合混料搅拌机械系统设备厂家 | 早报网| 中直网_行业门户-行业人专业的交流平台!| 净化车间装修_合肥厂房无尘室设计_合肥工厂洁净工程装修公司-安徽盛世和居装饰 | 成都租车_成都租车公司_成都租车网_众行宝| 餐饮小吃技术培训-火锅串串香培训「何小胖培训」_成都点石成金[官网] | 无线联网门锁|校园联网门锁|学校智能门锁|公租房智能门锁|保障房管理系统-KEENZY中科易安 | 等离子表面处理机-等离子表面活化机-真空等离子清洗机-深圳市东信高科自动化设备有限公司 | 工业洗衣机_工业洗涤设备_上海力净工业洗衣机厂家-洗涤设备首页 bkzzy在职研究生网 - 在职研究生招生信息咨询平台 | 污水处理设备-海普欧环保集团有限公司 |