当前位置: 代码迷 >> Web前端 >> checkbox值取舍
  详细解决方案

checkbox值取舍

热度:93   发布时间:2012-10-06 17:34:01.0
checkbox值选择
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>
  相关解决方案