jQuery對select的操作

2021-06-02 10:11:04 字數 957 閱讀 5170

獲取select :

獲取select 選中的 text :

$("#selectid").find("option:selected").text();

獲取select選中的 value:

$("#selectid").val();

獲取select選中的索引:

$("#selectid").get(0).selectedindex;

設定select:

設定select 選中的索引:

$("#selectid").get(0).selectedindex=index;//index為索引值

設定select 選中的value:

$("#selectid").attr("value","normal「);

$("#selectid").val("normal");

$("#selectid").get(0).value = value;

設定select 選中的text:

$("#select_id option[text='jquery']").attr("selected", true);

設定select option項:

$("#selectid").prepend("請選擇"); //在前面插入一項option

$("#selectid option:last").remove(); //刪除索引值最大的option

$("#selectid option[index='0']").remove();//刪除索引值為0的option

$("#selectid option[value='3']").remove(); //刪除值為3的option

$("#selectid option[text='4']").remove(); //刪除text值為4的option

清空 select:

$("#selectid").empty();

jquery對select下拉框的基本操作大全

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

jQuery 對 Select 的操作

取得下拉列表的選取值 testselect option selected text 或 testselect find option selected text 或 testselect val 記性不好的可以收藏下 1,下拉框 稍微解釋一下 1.select name country optio...

jquery 對select的操作

如題。使用js直接操作select。一般會使用到下面的幾個命令 var tmp document.getelementbyid select 建立option方法1 var tmpop document.createelementbytagname option tmp.value 1 建立opti...