jQuery對(duì)Select的操作大集合(收藏)
1.jQuery添加/刪除Select的Option項(xiàng):
2.$("#select_id").append("<option value='Value'>Text</option>"); //為Select追加一個(gè)Option(下拉項(xiàng))
3.$("#select_id").prepend("<option value='0'>請(qǐng)選擇</option>"); //為Select插入一個(gè)Option(第一個(gè)位置)
4.$("#select_id option:last").remove(); //刪除Select中索引值最大Option(最后一個(gè))
5.$("#select_id option[index='0']").remove(); //刪除Select中索引值為0的Option(第一個(gè))
6.$("#select_id option[value='3']").remove(); //刪除Select中Value='3'的Option
7.$("#select_id option[text='4']").remove(); //刪除Select中Text='4'的Option
8.$("#select_id").empty(); //清空select中的option
1.jQuery獲取Select選擇的Text和Value:
2.$("#select_id").change(function(){//code...}); //為Select添加事件,當(dāng)選擇其中一項(xiàng)時(shí)觸發(fā)
3.var checkText=$("#select_id").find("option:selected").text(); //獲取Select選擇的Text
4.var checkValue=$("#select_id").val(); //獲取Select選擇的Value
5.var checkIndex=$("#select_id ").get(0).selectedIndex; //獲取Select選擇的索引值
6.var maxIndex=$("#select_id option:last").attr("index"); //獲取Select最大的索引值 jQuery設(shè)置Select選擇的Text和Value:
相關(guān)文章
使用jQuery實(shí)現(xiàn)input數(shù)值增量和減量的方法
這篇文章主要介紹了使用jQuery實(shí)現(xiàn)input數(shù)值增量和減量的方法,實(shí)例分析了Bootstrap TouchSpin插件的用法,是非常實(shí)用的技巧,需要的朋友可以參考下2015-01-01基于jquery實(shí)現(xiàn)簡(jiǎn)單的手風(fēng)琴特效
這篇文章主要介紹了基于jquery實(shí)現(xiàn)簡(jiǎn)單的手風(fēng)琴特效,需要的朋友可以參考下2015-11-11jquery配合css簡(jiǎn)單實(shí)現(xiàn)返回頂部效果
返回頂部效果想必大家并不陌生吧,其實(shí)實(shí)現(xiàn)方法有很多,在本文為大家介紹下使用jquery是如何輕易實(shí)現(xiàn)的,感興趣的朋友可以參考下2013-09-09jquery實(shí)現(xiàn)通用的內(nèi)容漸顯Tab選項(xiàng)卡效果
這篇文章主要介紹了jquery實(shí)現(xiàn)通用的內(nèi)容漸顯Tab選項(xiàng)卡效果,涉及jquery通過(guò)時(shí)間函數(shù)定時(shí)觸發(fā)頁(yè)面元素樣式變換的功能,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-09-09基于jquery的大眾點(diǎn)評(píng),分類導(dǎo)航實(shí)現(xiàn)代碼
基于jquery的大眾點(diǎn)評(píng),分類導(dǎo)航實(shí)現(xiàn)代碼,需要的朋友可以參考下。2011-08-08