首页 > 网站 > WEB开发 > 正文

Javascript关于树形菜单,Checkbox的全选

2024-04-27 14:03:47
字体:
来源:转载
供稿:网友
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Checkbox</title>
<meta name="generator" content="editplus" />
<style type="text/CSS">
body{font-size:12px;}
.panel {BORDER-RIGHT: #d4d0c8 3px double; OVERFLOW-Y: scroll; PADDING-LEFT: 5px; BORDER-TOP: #d4d0c8 2px ridge; BORDER-LEFT: #808080 2px ridge; BORDER-BOTTOM: #d4d0c8 3px double; HEIGHT: 250px}
.parent {PADDING-LEFT: 15px}
.child {PADDING-LEFT: 30px}
</style>
<script type="text/javascript">
// CheckBoxList 选框
function chkbox(obj)
{
        var chk = obj.all.tags("input");
        var count = chk.length;
        if (event.srcElement.tagName == "INPUT")
        {
                with (event.srcElement)
                {
                        // 全选
                        if (parentElement.pid == "-1")
                        {
                                for (var i=0; i<count; i++)
                                {
                                        chk[i].checked = checked;
                                }
                        }
                        // 父类
                        if (parentElement.pid == "0")
                        {
                                chk[0].checked = checked;
                                for (var i=0; i<count; i++)
                                {
                                        if (chk[i].parentElement.pid == parentElement.id) chk[i].checked = checked
                                        if (!chk[i].checked) chk[0].checked = false;
                                }
                        }
                        // 子类
                        if (parentElement.pid > "0")
                        {
                                chk[0].checked = checked;
                                var parentObj;        // 父类对象
                                for (var i=0; i<count; i++)
                                {
                                        if (chk[i].parentElement.id == parentElement.pid)        // 选中父类
                                        {
                                                parentObj = chk[i];        // http://www.vevb.com/tools/wangzhansuduceshi.asp 将父类对象赋于一个变量
                                                chk[i].checked = checked;
                                        }
                                        if (chk[i].parentElement.pid == parentElement.pid)        // 如果子类中有一项没有选中,将父类的选中取消
                                        {
                                                if (!chk[i].checked) parentObj.checked = false;
                                        }
                                        if (!chk[i].checked) chk[0].checked = false;
                                }
                        } // if end
                } // with end
        } // if end
}
</script>
</head>
<body>
<SPAN>请选择要重新发布的商品类别</SPAN><BR>
<SPAN style="WIDTH: 200px; DISPLAY: inline-block" id=chkClass oncontextmenu="return false;" onselectstart="return false" class=panel onclick=chkbox(this);>
<SPAN id=-1 pid="-1"><INPUT id=chkClass_0 type=checkbox name=chkClass$0><LABEL for=chkClass_0>全选</LABEL></SPAN><BR>
<SPAN id=1 class=parent pid="0"><INPUT id=chkClass_1 type=checkbox name=chkClass$1><LABEL for=chkClass_1>房屋信息</LABEL></SPAN><BR>
        <SPAN id=10 class=child pid="1"><INPUT id=chkClass_2 type=checkbox name=chkClass$2><LABEL for=chkClass_2>├整套出租</LABEL></SPAN><BR>
        <SPAN id=11 class=child pid="1"><INPUT id=chkClass_3 type=checkbox name=chkClass$3><LABEL for=chkClass_3>├单间出租</LABEL></SPAN><BR>
        <SPAN id=12 class=child pid="1"><INPUT id=chkClass_4 type=checkbox name=chkClass$4><LABEL for=chkClass_4>├短期出租</LABEL></SPAN><BR>
        <SPAN id=13 class=child pid="1"><INPUT id=chkClass_5 type=checkbox name=chkClass$5><LABEL for=chkClass_5>├求租房屋</LABEL></SPAN><BR>
        <SPAN id=14 class=child pid="1"><INPUT id=chkClass_6 type=checkbox name=chkClass$6><LABEL for=chkClass_6>├房屋出售</LABEL></SPAN><BR>
<SPAN id=2 class=parent pid="0"><INPUT id=chkClass_7 type=checkbox name=chkClass$7><LABEL for=chkClass_7>教育培训</LABEL></SPAN><BR>
        <SPAN id=15 class=child pid="2"><INPUT id=chkClass_8 type=checkbox name=chkClass$8><LABEL for=chkClass_8>├语言课程</LABEL></SPAN><BR>
        <SPAN id=16 class=child pid="2"><INPUT id=chkClass_9 type=checkbox name=chkClass$9><LABEL for=chkClass_9>├商业课程</LABEL></SPAN><BR>
        <SPAN id=17 class=child pid="2"><INPUT id=chkClass_10 type=checkbox name=chkClass$10><LABEL for=chkClass_10>├证书培训</LABEL></SPAN><BR>
        <SPAN id=18 class=child pid="2"><INPUT id=chkClass_11 type=checkbox name=chkClass$11><LABEL for=chkClass_11>├家教辅导</LABEL></SPAN><BR>
        <SPAN id=19 class=child pid="2"><INPUT id=chkClass_12 type=checkbox name=chkClass$12><LABEL for=chkClass_12>├教育中介</LABEL></SPAN><BR>
        <SPAN id=20 class=child pid="2"><INPUT id=chkClass_13 type=checkbox name=chkClass$13><LABEL for=chkClass_13>├其它教育相关</LABEL></SPAN><BR>
<SPAN id=3 class=parent pid="0"><INPUT id=chkClass_14 type=checkbox name=chkClass$14><LABEL for=chkClass_14>招聘求职</LABEL></SPAN><BR>
        <SPAN id=21 class=child pid="3"><INPUT id=chkClass_15 type=checkbox name=chkClass$15><LABEL for=chkClass_15>├招聘信息</LABEL></SPAN><BR>
        <SPAN id=22 class=child pid="3"><INPUT id=chkClass_16 type=checkbox name=chkClass$16><LABEL for=chkClass_16>├求职信息</LABEL></SPAN><BR>
<SPAN id=6 class=parent pid="0"><INPUT id=chkClass_17 type=checkbox name=chkClass$17><LABEL for=chkClass_17>居家用品</LABEL></SPAN><BR>
<SPAN id=23 class=child pid="6"><INPUT
id=chkClass_18 type=checkbox name=chkClass$18><LABEL
for=chkClass_18>├家用电器</LABEL></SPAN><BR><SPAN id=24 class=child pid="6"><INPUT
id=chkClass_19 type=checkbox name=chkClass$19><LABEL
for=chkClass_19>├家具</LABEL></SPAN><BR><SPAN id=25 class=child pid="6"><INPUT
id=chkClass_20 type=checkbox name=chkClass$20><LABEL
for=chkClass_20>├厨具</LABEL></SPAN><BR><SPAN id=26 class=child pid="6"><INPUT
id=chkClass_21 type=checkbox name=chkClass$21><LABEL
for=chkClass_21>├床上用品</LABEL></SPAN><BR><SPAN id=27 class=child pid="6"><INPUT
id=chkClass_22 type=checkbox name=chkClass$22><LABEL
for=chkClass_22>├其它居家相关</LABEL></SPAN><BR><SPAN id=7 class=parent pid="0"><INPUT
id=chkClass_23 type=checkbox name=chkClass$23><LABEL
for=chkClass_23>美食餐馆</LABEL></SPAN><BR><SPAN id=28 class=child pid="7"><INPUT
id=chkClass_24 type=checkbox name=chkClass$24><LABEL
for=chkClass_24>├餐馆</LABEL></SPAN><BR><SPAN id=29 class=child pid="7"><INPUT
id=chkClass_25 type=checkbox name=chkClass$25><LABEL
for=chkClass_25>├外卖服务</LABEL></SPAN><BR><SPAN id=8 class=parent pid="0"><INPUT
id=chkClass_26 type=checkbox name=chkClass$26><LABEL
for=chkClass_26>服饰美容</LABEL></SPAN><BR><SPAN id=30 class=child pid="8"><INPUT
id=chkClass_27 type=checkbox name=chkClass$27><LABEL
for=chkClass_27>├时尚服装</LABEL></SPAN><BR><SPAN id=31 class=child pid="8"><INPUT
id=chkClass_28 type=checkbox name=chkClass$28><LABEL
for=chkClass_28>├流行饰品</LABEL></SPAN><BR><SPAN id=32 class=child pid="8"><INPUT
id=chkClass_29 type=checkbox name=chkClass$29><LABEL
for=chkClass_29>├包包鞋帽</LABEL></SPAN><BR><SPAN id=33 class=child pid="8"><INPUT
id=chkClass_30 type=checkbox name=chkClass$30><LABEL
for=chkClass_30>├美容护肤</LABEL></SPAN><BR><SPAN id=34 class=child pid="8"><INPUT
id=chkClass_31 type=checkbox name=chkClass$31><LABEL
for=chkClass_31>├其它服饰美容相关</LABEL></SPAN><BR><SPAN id=9 class=parent
pid="0"><INPUT id=chkClass_32 type=checkbox name=chkClass$32><LABEL
for=chkClass_32>电子通讯</LABEL></SPAN><BR><SPAN id=35 class=child pid="9"><INPUT
id=chkClass_33 type=checkbox name=chkClass$33><LABEL
for=chkClass_33>├手机</LABEL></SPAN><BR><SPAN id=36 class=child pid="9"><INPUT
id=chkClass_34 type=checkbox name=chkClass$34><LABEL
for=chkClass_34>├数码相机</LABEL></SPAN><BR><SPAN id=37 class=child pid="9"><INPUT
id=chkClass_35 type=checkbox name=chkClass$35><LABEL
for=chkClass_35>├随身听,耳机音响</LABEL></SPAN><BR><SPAN id=38 class=child
pid="9"><INPUT id=chkClass_36 type=checkbox name=chkClass$36><LABEL
for=chkClass_36>├电脑配件</LABEL></SPAN><BR><SPAN id=39 class=child pid="9"><INPUT
id=chkClass_37 type=checkbox name=chkClass$37><LABEL
for=chkClass_37>├笔记本台式机</LABEL></SPAN><BR><SPAN id=40 class=child pid="9"><INPUT
id=chkClass_38 type=checkbox name=chkClass$38><LABEL
for=chkClass_38>├电脑维修</LABEL></SPAN><BR><SPAN id=41 class=child pid="9"><INPUT
id=chkClass_39 type=checkbox name=chkClass$39><LABEL
for=chkClass_39>├其它电子相关</LABEL></SPAN></SPAN>    
</body>
</html>
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表