function selAll(classname) {
if ($("#" + classname).attr("checked")) {
$("." + classname).attr("checked",true);
} else {
$("." + classname).removeAttr("checked");
}
}
function sel(classname) {
var cont = 0;
$("." + classname).each(function(){
if($(this).attr("checked")){
cont ++;
}
})
if(cont > 0){
var c = document.getElementById(classname);
c.checked = true;
}else{
document.getElementById(classname).checked = false;
}
}
function ok(){
var msg="";
$("#checkboxDemo input[type=checkbox]").each(function(){
if($(this).attr("checked")){
msg=msg+","+$(this).val()
}
})
if(msg.length > 0)
msg = msg.substring(1,msg.length);
}
html:
<input type="checkbox" id="m1" value="1" onclick="selAll('m1')"/>系统管理<ul>
<li><input class="m1" type="checkbox" value="4" onclick="sel('m1')" />用户管理</li>
<li><input class="m1" type="checkbox" value="6" onclick="sel('m1')" />系统刷新</li>
</ul>