selected对话框全选

时间:2021-09-08 14:39:17

selected对话框全选

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<div id="checklist">
<input type="checkbox" value="" /> 篮球
<input type="checkbox" value="" /> 足球
<input type="checkbox" value="" /> 羽毛球
</div>
<div>
<input type="button" value="全选" id="selectall">
<input type="button" value="不选" id="unselect">
<input type="button" value="反选" id="reverseall">
</div> <script type="text/javascript" src="jquery-2.2.3.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$("#selectall").click(function () {
$("#checklist :checkbox").attr('checked',true)
//$("#checklist").children("input[type='checkbox']").attr('checked',true)
}) $("#unselect").click(function () {
$("#checklist input[type='checkbox']").attr('checked',false)
// $("#checklist").children("input[type='checkbox']").attr('checked',false)
})
}) </script>
</body>
</html>