<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>多选反选</title>
<script type="text/javascript" src="../js/jquery-1.4.2.js"></script>
<script type="text/javascript">
window.οnlοad=function(){
$("#yesorno").click(function(){
$("input[name=sport]").attr("checked",$(this).attr("checked"));
});
$("#allselect").click(function(){
$("input[name=sport]").attr("checked",true);
});
$("#nothingselect").click(function(){
$("input[name=sport]").attr("checked",null);
});
$("#reverseselect").click(function(){
$("input[name=sport]").each(function(){
if($(this).attr("checked")){ //if(this.checked){
$(this).attr("checked",null);
}else{
$(this).attr("checked",true);
}
});
});
};
</script>
</head>
<body>
<input type="checkbox" id="yesorno"/>全选/全不选 <br/>
<input type="checkbox" name="sport" id="football" />足球
<input type="checkbox" name="sport" id="basketball"/>蓝球
<input type="checkbox" name="sport" id="volleyball"/>排球
<input type="checkbox" name="sport" id="tennis"/>网球
<br/>
<input type="button" id="allselect" value="全选"/>
<input type="button" id="nothingselect" value="全不选"/>
<input type="button" id="reverseselect" value="反选"/>
</body>
</html>
图片效果: