<HEAD>
<script type="text/javascript" src="./jquery-1.11.1.js"></script>
<script type="text/javascript">
$(function(){
var checkbox = $("#test :checkbox")
$("#test :checkbox").click(function(){
var opchek = $(this)
var level = parseInt(opchek.attr("level"))
$.each(checkbox, function(){
var _this = $(this)
if(parseInt(_this.attr("level"))< level){
if(opchek.prop("checked")){
_this.prop("checked",true)//这个方法好像是1.8+的jquery才有的
_this.attr("disabled",true)
}else{
var prevLevel = level - 1
$("#test :checkbox[level='"+prevLevel+"']").attr("disabled",false)
}
}
})
})
})
</script>
</HEAD>
<BODY>
<div id="test">
<input type="checkbox" id="a" level="1">查看</input>
<input type="checkbox" id="b" level="2">添加</input>
<input type="checkbox" id="c" level="3">修改</input>
<input type="checkbox" id="d" level="4">完全控制</input>
</div>
</BODY>
</HTML>
$("#all").click(function(){if(this.checked){
$("input[type='checkbox']").attr("checked", true)
}else{
$("input[type='checkbox").attr("checked", false)
}
})
全选按钮的ID为“all”