jquery实现checkbox全选和反选

<!DOCTYPE html>
<html lang="zh-cn">
<head>
	<meta charset="UTF-8">
	<title>全选反选</title>
	<script src="jquery.min.js"></script>
	<script>
		function checkAll(obj){
		    $("#box input[type='checkbox']").prop('checked', $(obj).prop('checked'));
		}
	</script>
</head>
<body>
	<div class="test" style="width: 500px;text-align: center;" >
		<div id="box">
		    <input type="checkbox" οnclick="checkAll(this)">全选<br><br>
		    <input type="checkbox"><br>
		    <input type="checkbox"><br>
		    <input type="checkbox"><br>
		    <input type="checkbox"><br>
		    <input type="checkbox"><br>
		    <input type="checkbox"><br>
		    <input type="checkbox"><br>
		    <input type="checkbox"><br>
		    <input type="checkbox"><br>
		</div>
	</div>
</body>
</html>

posted @ 2024-05-08 17:11  燕鹏  阅读(13)  评论(0)    收藏  举报  来源