带有asp.net的javascript复选框 [英] Check box javascript with asp.net

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

问题描述

有两种复选框......当checkbox1是选择,显示它是什么隐藏...它是当checkbox2被检查隐藏罚款或特别申明,不要显示anything.But当它是检查checkbox1,我提出取消选中显示它不是隐藏的块

<input type="checkbox" ID="chebox1"   runat="server" class="check"  onclick="select()"/&gt
<input type="checkbox" ID="chebox2"   runat="server" class="check"  onclick="unselect()"/&gt



<pre lang="xml"><script type="text/javascript">

   function select() {


        document.getElementById("div").style.display = "block";

   }

     function unselect(){


         document.getElementById("div").style.display = "none";
    }
    </script>




解决方案

这种设计是错误的.如果两个都检查怎么办?有一个复选框,让您的代码检查是否已选中,并基于此进行隐藏/取消隐藏.您可以执行select(this)将您的复选框传递到方法中,而无需查找它.不能很好地理解您的问题.

笔记-
如果要检查复选框的状态,然后隐藏或显示,则可以将复选框ID传递给函数. (选中的属性)


尝试使用以下代码

function select()
{

  if (document.getElementById("checkbox1").checked)
    document.getElementById("div1").style.display = ''''
  else
    document.getElementById("div1").style.display = ''none''
}


function unselect(){
{
   if (document.getElementById("checkbox2").checked)
   document.getElementById("div1").style.display = ''none''
 else
   document.getElementById("div1").style.display = ''''
}


There two checkbox...When checkbox1 is select, display what it is hidden...it is fine when checkbox2 is check is hidden or don''t show anything.But when it is check checkbox1 , i made uncheck the display it is not hidden the block

&lt;input type="checkbox" ID="chebox1"   runat="server" class="check"  onclick="select()"/&gt
&lt;input type="checkbox" ID="chebox2"   runat="server" class="check"  onclick="unselect()"/&gt



<pre lang="xml"><script type="text/javascript">

   function select() {


        document.getElementById("div").style.display = "block";

   }

     function unselect(){


         document.getElementById("div").style.display = "none";
    }
    </script>




解决方案

This design is wrong. What if both are checked ? Have one checkbox and make your code check if it''s checked and hide/unhide based on that. You can do select(this) to pass your checkbox in to the method and not need to look it up.


avoid using select() as user function name , but still I didn''t understand your problem well.

notes -
if you want to check the state of checkbox and then hide or display you can pass the checkbox id to function. (checked property)


Try using following code

function select()
{

  if (document.getElementById("checkbox1").checked)
    document.getElementById("div1").style.display = ''''
  else
    document.getElementById("div1").style.display = ''none''
}


function unselect(){
{
   if (document.getElementById("checkbox2").checked)
   document.getElementById("div1").style.display = ''none''
 else
   document.getElementById("div1").style.display = ''''
}


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

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