document.getElementById("chkBox")为null [英] document.getElementById("chkBox") is null

查看:85
本文介绍了document.getElementById("chkBox")为null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨..我遇到了document.getElementById("chkBox")为空的问题.
这是我的javascript:

Hi.. i got problems with document.getElementById("chkBox") is null.
here is my javascript :

function Check()
        {
              if(document.getElementById("chkBox").checked=true)
              {
                  document.getElementById("NA").style.display = "none";

              }


其他{}}

html代码:


else{}}

html code:

<form name="check">
                        <input type="checkbox" name="chkBox" onclick="Check()" runat="server"/>
                       
                     </form>

推荐答案

<input type="checkbox" name="chkBox" onclick="Check()" runat="server"/>


1.您的复选框是服务器控件
2.您尚未为控件提供任何ID,并试图通过getElementbyID
访问
根据您的代码,进行以下更改,它应该可以工作:
1.删​​除runat ="server"
2.输入ID ="chkBox"


1. Your checkbox is a server control
2. You have not given any ID to your control and trying to access via getElementbyID

Based on your code, make the following change and it should work:
1. Remove runat="server"
2. Put ID="chkBox"


你好,

我还注意到您正在使用document.getElement ById ,但是没有id属性.

< input type ="checkbox" id ="chkBox" name ="chkBox" onclick ="Check()" runat ="server"/>
hello,

I also noticed that you are using document.getElementById but there is no id attribute.

<input type="checkbox" id="chkBox" name="chkBox" onclick="Check()" runat="server"/>


Javascript:

Javascript:

<script>
function Check()
{
if(document.getElementById("chkBox").checked)
{
  document.getElementById("NA").style.display = "none";
}
else
{
  document.getElementById("NA").style.display = "block";
}
}
</script>



HTML



HTML

<form name="check">
<input type="checkbox" name="chkBox" onclick="Check()" runat="server"/>Click
</form>
<div id="NA">This is test</div>



这适用于我的浏览器



This works on my browser


这篇关于document.getElementById("chkBox")为null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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