亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

JQuery給select添加/刪除節(jié)點(diǎn)的實(shí)現(xiàn)代碼

 更新時(shí)間:2016年04月26日 14:54:24   投稿:jingxian  
下面小編就為大家?guī)硪黄狫Query給select添加/刪除節(jié)點(diǎn)的實(shí)現(xiàn)代碼。小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考

jQuery獲取Select選擇的Text和Value:

var checkText=jQuery("#select_id").find("option:selected").text(); //獲取Select選擇的Text
var checkValue=jQuery("#select_id").val(); //獲取Select選擇的option Value
var checkIndex=jQuery("#select_id ").get(0).selectedIndex; //獲取Select選擇的索引值
var maxIndex=jQuery("#select_id option:last").attr("index"); //獲取Select最大的索引值

jQuery添加/刪除Select的Option項(xiàng):
jQuery("#select_id").append("<option value='Value'>Text</option>"); //為Select追加一個(gè)Option(下拉項(xiàng))
jQuery("#select_id").prepend("<option value='0'>請選擇</option>"); //為Select插入一個(gè)Option(第一個(gè)位置)
jQuery("#select_id option:last").remove(); //刪除Select中索引值最大Option(最后一個(gè))
jQuery("#select_id option[index='0']").remove(); //刪除Select中索引值為0的Option(第一個(gè))
jQuery("#select_id option[value='3']").remove(); //刪除Select中Value='3'的Option
jQuery("#select_id option[text='4']").remove(); //刪除Select中Text='4'的Option

內(nèi)容清空:
jQuery("#select_id").empty();

以上這篇JQuery給select添加/刪除節(jié)點(diǎn)的實(shí)現(xiàn)代碼就是小編分享給大家的全部內(nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論