checkbox遍历,显示对应内容

<input id="Checkbox1" name="ZGXZ" type="checkbox" οnclick="switchdiv();" >
                                        <label for="Checkbox1">
                                            人员信息</label>
                                        <input id="Checkbox2" name="ZGXZ" type="checkbox" οnclick="switchdiv();" >
                                        <label for="Checkbox2">
                                            学历信息</label>
                                        <input id="Checkbox3" name="ZGXZ" type="checkbox"οnclick="switchdiv();" >
                                        <label for="Checkbox3">
                                            晋升信息</label>
                                        <input id="Checkbox4" name="ZGXZ" type="checkbox"οnclick="switchdiv();" >
                                        <label for="Checkbox4">
                                            科室信息</label>
                                        <input id="Checkbox5" name="ZGXZ" type="checkbox"οnclick="switchdiv();" >
                                        <label for="Checkbox5">
                                            学术活动</label>
                                     

这是5个checkbox,分别对应以下5个div

<div id="xm1" style="display:block;">
    <h1  align="center">人员信息</h1>
        <table  id="table" style="margin: auto; text-align: center;" class="form">
            <tr>第一个
            </tr>
        </table>
        </div>

        <div id="xm2" style="display:block;">
        <h1   align="center">学历信息</h1>
        <table  id="table1" style="margin: auto; text-align: center;" class="form">
            <tr>
                第二个</tr>
        </table>
        </div>

        <div id="xm3" style="display:block;">
        <h1  align="center">晋升信息</h1>
        <table  id="table2" style="margin: auto; text-align: center;" class="form">
            <tr>
              第三个
              </tr>
        </table>
        </div>

        <div id="xm4" style="display:block;">
         <h1  align="center">科室信息</h1>
        <table  id="table3" style="margin: auto; text-align: center;" class="form">
            <tr>第四个</tr>
        </table>
        </div>

        <div id="xm5" style="display:block;">
        <h1  align="center">学术活动</h1>
        <table  id="table4" style="margin: auto; text-align: center;" class="form">
            <tr>第五个</tr>
        </table>
        </div>

以下为checkbox的点击事件:

<script type="text/javascript">        
function switchdiv() {
            for (var i = 1;; i++) {
                var ele = document.getElementById('xm' + i);
                var ck = document.getElementById('Checkbox' + i);
                if (!ele) {
                    break;
                }
                else {
                    if (ck.checked) {
                        ele.style.display = 'block';
                    }
                    else {
                        ele.style.display = 'none';
                    }
                }
            }
        }
</script>

over……

另附上我之前查到的参考资料,写的也很好,以后可能会用到:

http://bbs.blueidea.com/thread-3064938-1-1.html

https://www.cnblogs.com/lwx521/p/7616784.html

http://bbs.csdn.net/topics/390885802

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值