首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > Web前端 >

checkbox值取舍

2012-10-06 
checkbox值选择function selAll(classname) {if ($(# + classname).attr(checked)) { $(. + classna

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 type="checkbox" value="4" onclick="sel('m1')" />用户管理</li>
<li><input type="checkbox" value="6" onclick="sel('m1')" />系统刷新</li>
</ul>

热点排行