jquery獲取select選擇的文字與值

2022-05-21 22:00:10 字數 1077 閱讀 5742

1 獲取select :

2 獲取select 選中的 text :

3 4 1$("#ddlregtype").find("option:selected").text();

5 獲取select選中的 value:

6 7 1$("#ddlregtype ").val();

8 獲取select選中的索引:

9 10 1$("#ddlregtype ").get(0).selectedindex;

11 設定select:

12 設定select 選中的索引:

13 14 1$("#ddlregtype ").get(0).selectedindex=index;//index為索引值

15 設定select 選中的value:

16 17 1$("#ddlregtype ").attr("value","normal「); 2$("#ddlregtype ").val("normal"); 3$("#ddlregtype ").get(0).value = value;

18 設定select 選中的text:

19 20 幫助1varcount=$("#ddlregtype option").length; 2 for(vari=0;i

33 值得注意的是,不能直接寫成

34 35 1$(function()); 7 }); 8})

36 html:

37 38 12 3 選項1 4 選項2 5 選項3 6 選項4 7 選項5 8 選項6 9 選項7 10 11 12 選中新增到右邊》 13 全部新增到右邊》 14

15

16 17 18 19 20 《選中刪除到左邊 21 《全部刪除到左邊 22

23

jQuery獲取Select元素

這個表示 假如我們希望當選擇選擇第三類時 如果第四類中有資料則刪除,如果沒有資料第四類的商品中的為預設值。在後面學習了ajax技術後經常會使用到!獲取select 獲取select 選中的 text ddlregtype find option selected text 獲取select選中的 v...

select 全選和反選 jquery

checkbox id in shareuser 10 name shareuser value 10 10 checkbox id in shareuser 11 name shareuser value 11 11 checkbox id in shareuser 12 name shareus...

jQuery獲取select的值

獲取select的值 test class form control name code 請選擇option 使用型別option 前端型別option value road level 車道朝向option value lane direction 道路等級option select 獲取選擇的值...