复选框列表和复选框 [英] checkboxlist and checkbox

查看:109
本文介绍了复选框列表和复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在名为(设置,雇员,薪水)的页面上有3个复选框,并有4个设置选项,分别是公司,分支机构,名称,部门.对于这些,我已经添加了一个复选框,其中我添加了这些项目.我想如果我要检查复选框列表中的任何项目,则应选中设置复选框,而如果我们取消选中复选框列表的所有项目,则应不选中它(设置复选框).

I have 3 checkbox on the page named (setup ,employee, salary) and have 4 options for setup that are as follows company ,branch, designation, department. And for these i have taken a checkboxlist in that I have added these items. And I want that if i will check any item in checkboxlist then set checkbox should be checked and if we unchecked all the items of checkboxlist then it (checkbox for setup) should be unchecked.

推荐答案

您需要使用Javascript.这与全部检查"相同的功能

在设置复选框上单击以下脚本,它将选中已选中的设置项目.

You need to use Javascript. This is the same functionality like "check all"

call following javscript on setup checkbox click, it will select items of setup checkbox checked.

function CheckBoxListSelect()
{    
       var chkBoxList = document.getElementById("chkBoxList1");
        var chkBoxCount= chkBoxList.getElementsByTagName("input");
        for(var i=0;i<chkboxcount.length;i++)>
        {
            if (chkBoxCount[i].checked)
                chkBoxCount[i].checked = false;
            else
                chkBoxCount[i].checked = true;
        }
        
        return false; 
}




在这里,我尝试了一些符合您要求的代码,只需检查一次即可

Hi,

Here i tried some code for your requirement just check this once

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script language ="javascript" >
        function f1(ti) {
          
            var str = new String();
            str = ti;
            var str1 = str.split('_');
            var len = document.getElementById(str1[0]).rows.length;
           
            var asd = 0;
            for (var i = 0; i < parseInt(len); i++) {
                if (document.getElementById(str1[0]+'_'+i).checked) {
                    asd = 1;
                }
            }
            if (asd == 1) {
                document.getElementById("CheckBox1").checked = true;
            }
            else {
                document.getElementById("CheckBox1").checked = false;
            }
           
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:checkbox id="CheckBox1" runat="server" xmlns:asp="#unknown" />
        <asp:checkboxlist id="CheckBoxList1" runat="server" xmlns:asp="#unknown">
           <asp:listitem text="first" value="first" onclick="f1(this.id)"></asp:listitem>
           <asp:listitem text="secnd" value="secnd" onclick="f1(this.id)"></asp:listitem>
           <asp:listitem text="third" value="third" onclick="f1(this.id)"></asp:listitem>
           <asp:listitem text="forth" value="forth" onclick="f1(this.id)"></asp:listitem>
        </asp:checkboxlist>
    </div>
    </form>
</body>
</html>



我希望它也对您有用

最好的



I hope it works for you too

All the Best


这篇关于复选框列表和复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆