新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
jQuerySelect操作大集合
jQuery獲取Select選擇的Text和Value:
語法解釋:

創(chuàng)新互聯(lián)從2013年創(chuàng)立,是專業(yè)互聯(lián)網(wǎng)技術(shù)服務公司,擁有項目網(wǎng)站制作、網(wǎng)站設計網(wǎng)站策劃,項目實施與項目整合能力。我們以讓每一個夢想脫穎而出為使命,1280元聞喜做網(wǎng)站,已為上家服務,為聞喜各地企業(yè)和個人服務,聯(lián)系電話:18980820575
- $("#select_id").change(function(){//code...}); //為Select添加事件,當選擇其中一項時觸發(fā)
- var checkText=$("#select_id").find("option:selected").text(); //獲取Select選擇的Text
- var checkValue=$("#select_id").val(); //獲取Select選擇的Value
- var checkIndex=$("#select_id ").get(0).selectedIndex; //獲取Select選擇的索引值
- var maxIndex=$("#select_id option:last").attr("index"); //獲取Select***的索引值 jQuery設置Select選擇的Text和Value:
語法解釋:
- $("#select_id ").get(0).selectedIndex=1; //設置Select索引值為1的項選中
- $("#select_id ").val(4); //設置Select的Value值為4的項選中
- $("#select_id option[text='jQuery']").attr("selected", true); //設置Select的Text值為jQuery的項選中
jQuery添加/刪除Select的Option項:
語法解釋:
- $("#select_id").append(""); //為Select追加一個Option(下拉項)
- $("#select_id").prepend(""); //為Select插入一個Option(***個位置)
- $("#select_id option:last").remove(); //刪除Select中索引值***Option(***一個)
- $("#select_id option[index='0']").remove(); //刪除Select中索引值為0的Option(***個)
- $("#select_id option[value='3']").remove(); //刪除Select中Value='3'的Option
- $("#select_id option[text='4']").remove(); //刪除Select中Text='4'的Option
網(wǎng)站題目:jQuerySelect操作大集合
當前地址:http://www.dlmjj.cn/article/dhcjjeh.html


咨詢
建站咨詢
