一个表单里如果有若干个checkbox,jquery里哪个语句可以判定某一组checkbox是否被选择?
<input type='checkbox' name='a' value='a'/>a <input type='checkbox' name='a' value='a1'/>a1
<input type='checkbox' name='b' value='b'/>b <input type='checkbox' name='b' value='b1'/>b1
<input type='checkbox' name='c' value='c'/>c <input type='checkbox' name='c' value='c1'/>c1
<input type='checkbox' name='d' value='d'/>d <input type='checkbox' name='d' value='d1'/>d1
<input type='checkbox' name='e' value='e'/>e <input type='checkbox' name='e' value='e1'/>e1
谢谢
哪一组被选中是什么意思?获取被选中的checkbox增加:checked选择器就行了,然后遍历获取
<input type='checkbox' name='a' value='a' />a <input type='checkbox' name='a' value='a1' />a1
<input type='checkbox' name='b' value='b' />b <input type='checkbox' name='b' value='b1' />b1
<input type='checkbox' name='c' value='c' />c <input type='checkbox' name='c' value='c1' />c1
<input type='checkbox' name='d' value='d' />d <input type='checkbox' name='d' value='d1' />d1
<input type='checkbox' name='e' value='e' />e <input type='checkbox' name='e' value='e1' />e1
<br /><input type="button" value="获取选中的checkbox" onclick="getChecked()" />
<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.4.1.min.js"></script>
<script>
function getChecked() {
$(':checkbox:checked').each(function () {
alert(this.name+'\n'+this.value)
});
}
</script>
jquery:
$("input[type='checkbox']").attr('value')
返回结果:a1
$("input[type='checkbox']").is(':checked')
返回结果:选中=true,未选中=false
jquery:
$("input[type='checkbox']").attr('value')
返回结果:a1
$("input[type='checkbox']").is(':checked')
返回结果:选中=true,未选中=false
楼上正解,系统说要够10个字。