复选框选择问题,帮我跟踪我的程序 [英] checkbox selection problems, help me trace my program

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

问题描述

我的复选框选择有问题,我不知道如何构建程序,这将使这些txtboxes的选择正确所以这里是,

我有这里有四个复选框:chkAll,chkActivity,chkItem和chkService

I have a problem on the selections of my checkboxes, I don't know how to construct the program which will make the selections of these txtboxes correct so here it is,
I'm have four checkboxes here they are: chkAll, chkActivity, chkItem and chkService

<asp:CheckBox ID="chkAll" runat="server" Text="All" Checked="True" ForeColor="#333333" style="font-family: sans-serif" AutoPostBack="True" oncheckedchanged="chkAll_CheckedChanged"/>
    <asp:CheckBox ID="chkActivity" runat="server"  Text="Activity" ForeColor="#333333" style="font-family: sans-serif" AutoPostBack="True" oncheckedchanged="chkAll_CheckedChanged"/>
    <asp:CheckBox ID="chkItem" runat="server"  Text="Item" ForeColor="#333333" style="font-family: sans-serif" AutoPostBack="True" oncheckedchanged="chkAll_CheckedChanged"/>
    <asp:CheckBox ID="chkService" runat="server" Text="Service" ForeColor="#333333" style="font-family: sans-serif" AutoPostBack="True" oncheckedchanged="chkAll_CheckedChanged"/>



By默认选中或选中复选框==true,


By default the checkboxes are selected or checked == "true",

protected void Page_Load(object sender, EventArgs e)
   {
       chkAll.Checked = true;
       chkActivity.Checked = true;
       chkItem.Checked = true;
       chkService.Checked = true;



现在当我取消选择第一个chkAll含义时点击它以便它将取消选择,它将使所有其他3个chkActivity,chkItem和chkService也被取消选中/取消选择。

现在我的问题是如何选择单个文本框之后或者一个comnibations前一段时间取消选中的三个复选框中的任何一个请帮助我,我会非常感谢你的回复并感谢先进。

顺便说一句,我尝试使用这个嵌套循环的东西,但它不起作用,无论如何我只是发布它所以也许你可以改进它;


Now when I deselect the first one which is chkAll meaning clicking on it so it will deselect, it will make all the other 3 which are chkActivity, chkItem and chkService unchecked/deselected too.
Now my problem is how to select the individual textboxes after or a comnibations of any of the three checkboxes deselected awhile ago please help me, I would really aprreciate your response and thanks in advanced.
By the way I've tried using this nested loop thing but it doesn't work, anyway I'll just post it so maybe you could improve it;

protected void chkAll_CheckedChanged(object sender, EventArgs e)
   {
       if (chkAll.Checked)
       {
           chkActivity.Checked = true;
           chkItem.Checked = true;
           chkService.Checked = true;
       }
       else
       {
           if (chkActivity.Checked == false)
           {
               chkActivity.Checked = false;
           }
           else if (chkItem.Checked == false)
           {
               chkItem.Checked = false;
           }
           else if (chkService.Checked == false)
           {
               chkService.Checked = false;
           }
           else
           {
               chkActivity.Checked = false;
               chkItem.Checked = false;
               chkService.Checked = false;
           }
       }
   }

推荐答案

我用过这个:

I used this:
function NotAllByService() {
       var chkAct = document.getElementById('<%=chkActivity.ClientID %>');
       var chkServ = document.getElementById('<%=chkService.ClientID %>');
       var chkIte = document.getElementById('<%=chkItem.ClientID %>');
       if (chkServ.checked == false) {
           document.getElementById('<%=chkAll.ClientID %>').checked = false;
       }
       else {
           if (chkAct.checked == true & chkServ.checked == true & chkIte.checked == true) {
               document.getElementById('<%=chkAll.ClientID %>').checked = true;
           } else {
               document.getElementById('<%=chkAll.ClientID %>').checked = false;
           }
       }
   }

   function NotAllByActivity() {
       var chkAct = document.getElementById('<%=chkActivity.ClientID %>');
       var chkServ = document.getElementById('<%=chkService.ClientID %>');
       var chkIte = document.getElementById('<%=chkItem.ClientID %>');
       if (chkAct.checked == false) {
           document.getElementById('<%=chkAll.ClientID %>').checked = false;
       }
       else {
           if (chkAct.checked == true & chkServ.checked == true & chkIte.checked == true) {
               document.getElementById('<%=chkAll.ClientID %>').checked = true;
           } else {
               document.getElementById('<%=chkAll.ClientID %>').checked = false;
           }
       }
   }

   function NotAllByItem() {
       var chkIte = document.getElementById('<%=chkItem.ClientID %>');
       var chkServ = document.getElementById('<%=chkService.ClientID %>');
       var chkAct = document.getElementById('<%=chkActivity.ClientID %>');
       if (chkIte.checked == false) {
           document.getElementById('<%=chkAll.ClientID %>').checked = false;
       }
       else {
           if (chkAct.checked == true & chkServ.checked == true & chkIte.checked == true) {
               document.getElementById('<%=chkAll.ClientID %>').checked = true;
           } else {
               document.getElementById('<%=chkAll.ClientID %>').checked = false;
           }
       }

   }


美好的一天先生。当您检查chkAll复选框时,您可以通过javascript检查chkActivity,chkItem等,而不是调用回发;



将您的chkAll更改为此



Good day sir. Instead of calling a postback when you check the chkAll checkbox, you can just check the chkActivity, chkItem etc etc through javascript;

change your chkAll to this

<asp:checkbox id="chkAll" runat="server" checked="True" forecolor="#333333" text="All" style="font-family:sans-serif" onchange="searchCheckAll();" xmlns:asp="#unknown" />





然后在



then add this function between

<script type="text/javascript"> and </script>







function searchCheckAll() {
            if (document.getElementById('<%=chkAll.ClientID %>').checked == true) {
                document.getElementById('<%=chkActivity.ClientID %>').checked = true;
                document.getElementById('<%=chkItem.ClientID %>').checked = true;
                document.getElementById('<%=chkService.ClientID %>').checked = true;

            }
            
        }





如果有效,请告诉我。< br $> b $ b

爱G:)



Please let me know if this works.

Love G :)


我可以看到它吗?!!! :-)



真的,看到它很痛苦。如何编写这样的东西?



Can I unsee it?!!! :-)

Really, it's painful to see. How it's possible to write such thing?

if (chkActivity.Checked == false)
{
   chkActivity.Checked = false;
}



什么时候什么都不做?

你不应该写多余的if;当你有一些布尔值时,它就是


when essentially this does nothing?
And you should not write redundant "if"; when you have some Boolean value already it's

bool condition = //...
//...
chkActivity.Checked = condition;



以非废话,准确的方式白色代码,也许你不需要问这样的问题。 :-)



-SA


这篇关于复选框选择问题,帮我跟踪我的程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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