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

首頁 > 編程 > JavaScript > 正文

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

2019-11-20 22:34:34
字體:
來源:轉載
供稿:網友

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;  

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 多伦县| 乌兰浩特市| 南川市| 抚远县| 温宿县| 曲沃县| 宜川县| 温州市| 宁安市| 汝阳县| 临沭县| 陆河县| 苗栗市| 江陵县| 常山县| 东乌| 丹棱县| 宁强县| 阿拉善盟| 湘西| 晴隆县| 罗源县| 宿松县| 习水县| 连州市| 资阳市| 宁河县| 繁峙县| 沁阳市| 雷波县| 洛扎县| 威信县| 濉溪县| 朔州市| 临西县| 民乐县| 教育| 东乌珠穆沁旗| 且末县| 通州区| 平乡县|