JQuery獲取和設定Select選項常用方法總結

2022-09-17 17:24:19 字數 1112 閱讀 4112

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;i2>.$("#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. $("#cuschildtypeid").empty();

2>. $("#cuschildtypeid").get(0).options.length = 0;  

JQuery獲取和設定Select選項

jquery獲取和設定select選項 獲取select 獲取select 選中的 text ddlregtype find option selected text 獲取select選中的 value ddlregtype val 獲取select選中的索引 ddlregtype get 0 se...

JQuery獲取和設定Select選項

jquery獲取和設定select選項 獲取select 獲取select 選中的 text ddlregtype find option selected text 或者 ddlregtype find option selected text 獲取select選中的 value ddlregty...

JQuery獲取和設定Select選項

jquery獲取和設定select選項 獲取select 獲取select 選中的 text ddlregtype find option selected text 或者 ddlregtype find option selected text 獲取select選中的 value ddlregty...