`

jQuery实现CheckBox的全选与反选

阅读更多
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>jQuery实现CheckBox全选与反选</title>
<script src="http://code.jquery.com/jquery-1.4.4.min.js" type="text/javascript"></script>    
<script type="text/javascript">
	$(function() {
		$("#checkboxAll").click(function() {
			$('input[name="boxList"]').attr("checked",this.checked); 
		});
		var $boxList = $("input[name='boxList']");
		$boxList.click(function(){
			$("#checkboxAll").attr("checked",$boxList.length == $("input[name='boxList']:checked").length ? true : false);
		});
	});
</script>
</head>
<body>
	<div>
		<input type="checkbox" id="checkboxAll" />全选
		<input type="checkbox" name="boxList" />测试1
		<input type="checkbox" name="boxList" />测试2
		<input type="checkbox" name="boxList" />测试3
		<input type="checkbox" name="boxList" />测试4
	</div>
</body>
</html>
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics