jquery checkbox全选

来源:互联网 发布:淘宝k8分销平台可靠吗 编辑:程序博客网 时间:2024/05/29 17:53

jquery 使用prop() checkbox全选:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="">
<meta name="author" content="">
<link rel="icon" href="favicon.ico">
<title></title>
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"></script>
</head>
<body>
<input type="checkbox" id="all"> 全选
<div>
<input type="checkbox"> 类别1
<input type="checkbox"> 类别2
<input type="checkbox"> 类别3
<input type="checkbox"> 类别4
</div>
<script>
$(function () {
$('#all').click(function(){
$(this).siblings('div').find('input[type=checkbox]').prop('checked',$(this).prop('checked'));
})
})
</script>
</body>
</html>




原创粉丝点击