<html>
<head>
<script type="text/javascript" src="jquery-1.8.3.js"></script>
<script type="text/javascript">
$(function(){
$('#quanxuan').click(function(){
console.log($(":checkbox").attr('checked',true));
});
$('#fanxuan').click(function(){
console.log($("input:checked").attr('checked',false));
});
});
function reverseAll(){
$(':checkbox').each(function(){
var v = $(this).prop('checked')? false:true; /*三元运算: var v = 条件? 真值:假值
如果checked值为true v=false
如果checked值为false v=true
*/
$(this).prop('checked',v)
})
}
</script>
</head>
<body>
<form>
<input type="checkbox" />
<input type="checkbox" />
<input type="checkbox" />
<input type="checkbox" />
<input type="checkbox" />
<input type="checkbox" />
<input type="checkbox" />
<input type="checkbox" />
<input type="checkbox" />
<input type="button" id='quanxuan' value="全选" />
<input type="button" id='fanxuan' value="全不选" />
<input type="button" οnclick="reverseAll()" value="反选"/>
</form>
</body>
</html>
用jqurey实现简单的全选、全不选、反选
最新推荐文章于 2022-01-06 18:42:02 发布