乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

      js操作select 顯示option的文本

       融水公子 2022-11-16 發(fā)布于福建
      表白:黑白圣堂血天使,天劍鬼刀阿修羅。 
      講解對(duì)象:
      /js操作select 顯示option的文本
      作者:融水公子 rsgz
      ===

      今天有一個(gè)需求就是 怎么獲取這個(gè)下拉框列表的 選中的值呢?用js實(shí)現(xiàn)

      這里面簡單的思路就是

      select_ele = document.getElementById('select')
      index = select_ele.selectedIndex  // 1
      select_text = select_ele.options[index].text;  // "蕭炎"
      
      獲取其他option文本
      select_ele.options[0].text;
      select_ele.options[1].text;
      select_ele.options[2].text;
      
      獲取option長度
      select_ele.length //3
      
      獲取對(duì)應(yīng)option源碼
      select_ele.item(2) // <option value="goldfish" selected="">Goldfish</option>
      select_ele.namedItem('cat'));  // <option value="cat" name="cat">Cat</option>
      
      創(chuàng)建新option
      var Macaw = document.createElement("option");  // 創(chuàng)建元素
      Macaw.setAttribute("value", "macaw");
      var newContent = document.createTextNode("Macaw");   // 創(chuàng)建文本
      Macaw.appendChild(newContent);  // 文本放進(jìn)元素
      selectEle.add(Macaw, 1);// Macaw index為1   元素放進(jìn)select對(duì)象
      selectEle.remove(2);// cat 被刪除
      === 
      公眾號(hào):不浪仙人
      謝謝大家的支持!可以點(diǎn)擊我的頭像,進(jìn)入我的空間瀏覽更多文章呢。建議大家360doc[www.hbhlny.cn]注冊(cè)一個(gè)賬號(hào)登錄,里面真的有很多優(yōu)秀的文章,歡迎大家的到來。
      ---

        轉(zhuǎn)藏 分享 獻(xiàn)花(0

        0條評(píng)論

        發(fā)表

        請(qǐng)遵守用戶 評(píng)論公約

        類似文章 更多