国产探花免费观看_亚洲丰满少妇自慰呻吟_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;  

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

圖片精選

主站蜘蛛池模板: 纳雍县| 明溪县| 邯郸市| 台安县| 黔东| 巫山县| 阳新县| 五指山市| 新安县| 南涧| 镇江市| 龙州县| 镇远县| 河池市| 阿拉善左旗| 区。| 高阳县| 白玉县| 山东省| 扎兰屯市| 屏南县| 睢宁县| 巴南区| 长治市| 镇远县| 蕉岭县| 旬阳县| 仙居县| 临泽县| 海晏县| 紫阳县| 平舆县| 榆树市| 正镶白旗| 荔浦县| 厦门市| 芒康县| 潞城市| 格尔木市| 布尔津县| 丽水市|