如何检查< input type ="复选框"已被选中 [英] how to check if <input type="checkbox " has been selected

查看:107
本文介绍了如何检查< input type ="复选框"已被选中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

e.g。我有两个复选框,即CS和VB,我只想知道使用后面的代码选择哪一个。

解决方案

如果假设你有chkCS和chkVB作为复选框(假设它们是输入类型,可从服务器端访问)然后您可以使用以下代码检查它们是否被选中:



  if (chkCB.Checked ==  true 
{
Console .Write( 复选框CS被选中);
}
else {
Console.Write( 复选框CS未选中);
}





chkVB的方式相同。


你可以尝试这个 -

  bool  chkStatus =(Request.Form [  YourCheckboxId] ==   on)?  true  false ; 





希望,它会有所帮助:)


您好b $ b试试这个

 <   asp:CheckBox     runat   =  server    text   =  CS    OnClick   =  alert('CS');    /  >  
< asp:CheckBox < span class =code-attribute> runat = server text = VB OnClick = alert('VB'); / >





或试试这个





 function gh(msg){
alert(你被点击: + msg);
}


< asp:CheckBox ID = CheckBox1 runat = server 文本 = VB OnClick = gh('VB'); / >
< span class =code-keyword>< asp:CheckBox ID = CheckBox2 runat = server 文字 = CS OnClick = gh('CS'); / >



问候

Aravindb


e.g. I have two checkBoxes namely CS and VB and i just want to know which one is selected using code behind.

解决方案

If suppose you have chkCS and chkVB as checkboxes (assuming they are "input" type and are accessible from server side) then you can use the following code to check if they are checked or not:

if (chkCB.Checked == true)
{
    Console.Write("checkbox CS is checked");
}
else{
    Console.Write("checkbox CS is NOT checked");
}



Same way for chkVB.


You can try this-

bool chkStatus = (Request.Form["YourCheckboxId"] == "on") ? true : false;



Hope, it helps :)


Hi Try this

<asp:CheckBox runat="server" text="CS" OnClick="alert('CS');" />
<asp:CheckBox runat="server" text="VB" OnClick="alert('VB');" />



or try this


 function gh(msg) {
            alert("You are clicked : " + msg);
        }


<asp:CheckBox ID="CheckBox1" runat="server" Text="VB" OnClick="gh('VB');" />
<asp:CheckBox ID="CheckBox2" runat="server" Text="CS" OnClick="gh('CS');" />


Regards
Aravindb


这篇关于如何检查&lt; input type =&quot;复选框&quot;已被选中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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