国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 語言 > JavaScript > 正文

淺析JQuery獲取和設置Select選項的常用方法總結

2024-05-06 15:48:39
字體:
來源:轉載
供稿:網友
本篇文章是對JQuery獲取和設置Select選項的一些常用方法進行了匯總介紹,有需要的朋友可以參考一下

1.獲取select 選中的 text:
 $("#cusChildTypeId").find("option:selected").text();
 $("#cusChildTypeId option:selected").text()

2.獲取select選中的 value:
 $("#ddlRegType ").val();

3.獲取select選中的索引:
      $("#ddlRegType ").get(0).selectedIndex;

4.得到select項的個數  
 $("#cusChildTypeId").get(0).options.length

5.設置select 選中的索引:
     $("#cusChildTypeId").get(0).selectedIndex=index;//index為索引值

6.設置select 選中的value:
    $("#cusChildTypeId").attr("value","Normal");
    $("#cusChildTypeId").val("Normal");
    $("#cusChildTypeId").get(0).value = "Normal";

7.設置select 選中的text:
 1>.var count=$("#cusChildTypeId").get(0).options.length;
     for(var i=0;i<count;i++) 
         {          
  if($("#cusChildTypeId").get(0).options.text == text) 
         { 
             $("#cusChildTypeId").get(0).options.selected = true;
             break; 
         } 
        }

 2>.$("#cusChildTypeId").val(text);
    $("#cusChildTypeId").change();

8.向select中添加一項,顯示內容為text,值為value  
 $("#cusChildTypeId").get(0).options.add(new Option(text,value));

9.刪除select中值為value的項
        var count = $("#cusChildTypeId").size();          
        for(var i=0;i<count;i++)  
        {  
            if($("#cusChildTypeId").get(0).options[i].value == value)  
            {  
                $("#cusChildTypeId").get(0).remove(i);  
                break;  
            }
        }

10.清空 Select:
 1>. $("#cusChildTypeId").empty();
 2>. $("#cusChildTypeId").get(0).options.length = 0;  

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表

圖片精選

主站蜘蛛池模板: 安宁市| 康乐县| 瓮安县| 衡阳县| 奉新县| 台州市| 黄龙县| 乌拉特前旗| 保德县| 金昌市| 泸水县| 吉水县| 偏关县| 湖州市| 清河县| 西昌市| 澄迈县| 南和县| 泰来县| 博罗县| 台南市| 揭西县| 武乡县| 宁津县| 醴陵市| 南康市| 栾川县| 济阳县| 平湖市| 乐东| 苍溪县| 马尔康县| 大渡口区| 公安县| 庄浪县| 穆棱市| 河源市| 苍梧县| 揭东县| 杨浦区| 卓资县|