jquery 很灵活,checkbox radio标签选中的方法有很多,在这儿就例举三个常用的方法。
一,测试html
<div style="margin-top:150px;">
<input type='checkbox' name='test[]' class='checkbox' value='checkbox1'>checkbox1
<input type='checkbox' name='test[]' class='checkbox' value='checkbox2'>checkbox2
<input type='checkbox' name='test[]' class='checkbox' value='checkbox3'>checkbox3
</div>
<div style="margin-top:50px;">
<input type="radio" name="test1" value = "radio1" class='radio' >radio1
<input type="radio" name="test1" value = "radio2" class='radio' >radio2
<input type="radio" name="test1" value = "radio3" class='radio' >radio3
</div>
二,checkbok,radio选中
方法1,
//这二个方法属于一类
$('.checkbox:checked');
$('input[type^=checkbox]:checked');
方法2,
$('.checkbox').filter(':checked');
方法3
$('.checkbox').each(function(){
if($(this).is(":checked")){
alert($(this).val()+": is checked");
}else{
alert($(this).val()+": is not checked");
}
})
将上面的.checkbox换成.radio,就可以判断radio标签的选中了。
转载请注明
作者:海底苍鹰
地址:http://blog.51yip.com/jsjquery/1549.html