欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

淺析JQuery獲取和設(shè)置Select選項(xiàng)的常用方法總結(jié)

 更新時(shí)間:2013年07月04日 09:15:06   作者:  
本篇文章是對(duì)JQuery獲取和設(shè)置Select選項(xiàng)的一些常用方法進(jìn)行了匯總介紹,有需要的朋友可以參考一下

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項(xiàng)的個(gè)數(shù)
  
 $("#cusChildTypeId").get(0).options.length

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

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

7.設(shè)置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中添加一項(xiàng),顯示內(nèi)容為text,值為value
  
 $("#cusChildTypeId").get(0).options.add(new Option(text,value));

9.刪除select中值為value的項(xiàng)
        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;  

相關(guān)文章

最新評(píng)論