<!DOCTYPE html PUBLIC "//WC//DTD XHTML Transitional//EN" "
<html xmlns="
<head>
<meta httpequiv="ContentType" content="text/html; charset=utf" />
<title>復選框的全選反選全不選</title>
<style>
body{ margin:px;}
</style>
<script language="javascript" type="text/javascript" src="/script/jqueryminjs"></script>
<script>
$(function(){
$("input[value=全選]")click(function(){
$("input[type=checkbox]")attr("checked"true);
})
$("input[value=全不選]")click(function(){
$("input[type=checkbox]")attr("checked"false);
})
$("input[value=反選]")click(function(){
$("input[type=checkbox]")each(function(){
$(this)attr("checked"!$(this)attr("checked"));
})
})
})
</script>
</head>
<body>
<div id="div">
<input type="checkbox" />蘋果
<input type="checkbox" />香蕉
<input type="checkbox" />菠蘿
<input type="checkbox" />草莓
<input type="checkbox" />梨子<br />
<input type="button" value="全選" /><input type="button" value="反選" /><input type="button" value="全不選" />
</div>
</body>
</html>
From:http://tw.wingwit.com/Article/program/Java/JSP/201311/20606.html