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

Jquery操作radio,checkbox,select表單操作實(shí)現(xiàn)代碼

 更新時間:2010年04月27日 21:12:04   作者:  
Jquery操作radio,checkbox,select表單操作實(shí)現(xiàn)代碼,需要用jquery操作表單的朋友可以參考下。

一 、Select
jQuery獲取Select選擇的Text和Value:
1. $("#select_id").change(function(){//code...}); //為Select添加事件,當(dāng)選擇其中一項(xiàng)時觸發(fā)
2. var checkText=$("#select_id").find("option:selected").text(); //獲取Select選擇的Text
3. var checkValue=$("#select_id").val(); //獲取Select選擇的Value
4. var checkIndex=$("#select_id ").get(0).selectedIndex; //獲取Select選擇的索引值
5. var maxIndex=$("#select_id option:last").attr("index"); //獲取Select最大的索引值

jQuery設(shè)置Select選擇的Text和Value:
1. $("#select_id ").get(0).selectedIndex=1; //設(shè)置Select索引值為1的項(xiàng)選中
2. $("#select_id ").val(4); //設(shè)置Select的Value值為4的項(xiàng)選中
3. $("#select_id option[text='jQuery']").attr("selected", true); //設(shè)置Select的Text值為jQuery的項(xiàng)選中

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

二、Checkbox
全選/取消
jQuery.attr 獲取/設(shè)置對象的屬性值,如:
$("input[name='chk_list']").attr("checked"); //讀取所有name為'chk_list'對象的狀態(tài)(是否選中)
$("input[name='chk_list']").attr("checked",true); //設(shè)置所有name為'chk_list'對象的checked為true
$("#img_1").attr("src","test.jpg"); //設(shè)置ID為img_1的<img>src的值為'test.jpg'
$("#img_1").attr("src"); //讀取ID為img_1的<img>src值
下面的代碼是獲取上面實(shí)例中選中的checkbox的value值:
<script type="text/javascript">
var arrChk=$("input[name='chk_list'][checked]");
$(arrChk).each(function(){
window.alert(this.value);
});
});
</script>

1,獲取checkbox的value
$("#checkboxID").value或$("input[type='checkbox']").eq(n).attr("checked").value
2,設(shè)置選中項(xiàng)
$("input[type='checkbox']").eq(1).attr("checked")//設(shè)置第一個checkbox為選中的項(xiàng)
3,刪除所有checkbox
$("input[type='checkbox']").remove()
4,checkbox方法
$(document).ready(function() {
var check = $("input[type='checkbox']");
check.each(function(n) {
check.eq(n).bind("click", function() {
if (check.eq(n).attr("checked") != false) {
var value = check.eq(n).val();
alert(value);
}
else {
alert(check.eq(n).attr("checked"));
}
})
});
});

三、radio
1,獲取選中的value值
$("input[type='radio']:checked").val();
2,設(shè)置指定的項(xiàng)為當(dāng)前選中項(xiàng)
$("input[type='radio']").eq(1).attr("checked", true);//設(shè)置第二項(xiàng)為選中項(xiàng)
$("input[type='radio'][value='值']").attr("checked, true");

3,解決多個Radio

$("input[type='radio'][@name='rdoTest2']").eq(0).attr("checked", true);
學(xué)習(xí)筆記,以備后用。

運(yùn)行以后,請刷新下才能看到效果,保存到本地運(yùn)行,沒有任何問題。


[Ctrl+A 全選 注:引入外部Js需再刷新一下頁面才能執(zhí)行]

相關(guān)文章

最新評論