0x800a138f - javascript运行时错误:无法设置未定义或空引用的属性“已检查” [英] 0x800a138f - javascript runtime error: unable to set property 'checked' of undefined or null reference

查看:268
本文介绍了0x800a138f - javascript运行时错误:无法设置未定义或空引用的属性“已检查”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

< script type =   text / javascript lang =   javascript> 
function HeaderCheckBoxClick(复选框)
{
// var gridview = document.getElementById(gvlink);
var gridview = document .getElementById( <%= gvlink.ClientID%>< /跨度>);
for (i = 1 ; i< gridview.rows.length; i ++)>
{
gridview.rows [i] .cells [ 0 ]。getElementsByTagName( INPUT)[ 0 ]。checked = checkbox.checked;
}
}
function ChildCheckBoxClick(复选框)
{
var atleastoneCheckBoxUnchecked = false ;
var gridview = document .getElementById( gvlink);

for (i = 1 ; i< gridview.rows.length ; i ++)
{
if (gridview.rows [i] .cells [ 0 ]。getElementsByTagName( INPUT)[ 0 ]。checked == false
{
atleastoneCheckBoxUnchecked = true ;
break ;
}
}
gridview.rows [i] .cells [ 0 ]。getElementsByTagName( INPUT)[ 0 ]。checked =!atleastoneCheckBoxUnchecked;
}
< / script>





我尝试了什么:



我试图选择所有并取消选中所有复选框但是我收到错误,请帮帮我。



gridview.rows [i] .cells [0] .getElementsByTagName(INPUT)[0] .checked = checkbox.checked;



with the line line代码我得到错误

我们正在使用Visual Studio 2015.

解决方案

Quote:

0x800a138f - javascript运行时错误:无法设置未定义或空引用的属性'已检查'



您尝试将属性设置为'已检查'这不是一个复选框或无法检查的东西。



使用调试器来确切地检查对象是什么。



调试器允许你逐行跟踪执行,检查变量,你会看到有一点让它停止做你期望的事情。

调试器 - 维基百科,免费的百科全书 [ ^ ]

在Visual Studio 2010中掌握调试 - 初学者指南 [ ^ ]



调试器在这里向您展示您的代码正在做什么,您的任务是与它应该做什么进行比较。

当代码没有没有做到预期,你接近一个错误。


要么这个



 gridview .rows [i] .cells [0] .getElementsByTagName(INPUT)[0] 





是undefined\\\
ull,或者复选框是。使用浏览器的调试工具来检查DOM,看看你的DOM中有什么,以及为什么你找不到你的想法。我们没有您的页面或数据的其余部分,因此我们无法为您执行此操作,您确实需要学习调试代码。


我也面临同样的问题问题。

问题在于for循环标准

试试这个。

for(var i = 1; i< gridview.rows.length- 1;我++)>

<script type="text/javascript" lang="javascript">
        function HeaderCheckBoxClick(checkbox)
        {
            //var gridview = document.getElementById("gvlink");
            var gridview = document.getElementById("<%=gvlink.ClientID%>");
            for(i=1;i<gridview.rows.length;i++)>
            {
                gridview.rows[i].cells[0].getElementsByTagName("INPUT")[0].checked = checkbox.checked;
            }
        }
        function ChildCheckBoxClick(checkbox)
        {
            var atleastoneCheckBoxUnchecked = false;
            var gridview = document.getElementById("gvlink");

            for (i = 1; i < gridview.rows.length; i++)
            {
                if(gridview.rows[i].cells[0].getElementsByTagName("INPUT")[0].checked == false)
                {
                    atleastoneCheckBoxUnchecked = true;
                    break;
                }
            }
            gridview.rows[i].cells[0].getElementsByTagName("INPUT")[0].checked = !atleastoneCheckBoxUnchecked;
        }
    </script>



What I have tried:

Iam trying to select all and deselect all check boxes but iam getting the error,Please help me.

gridview.rows[i].cells[0].getElementsByTagName("INPUT")[0].checked = checkbox.checked;

with in the above line of code iam getting error
we are using Visual studio 2015.

解决方案

Quote:

0x800a138f - javascript runtime error: unable to set property 'checked' of undefined or null reference


You try to set the property 'checked' on something that is not a checkbox or something that can't be checked.

Use the debugger to exactly what is the object you try to check.

The debugger allow you to follow the execution line by line, inspect variables and you will see that there is a point where it stop doing what you expect.
Debugger - Wikipedia, the free encyclopedia[^]
Mastering Debugging in Visual Studio 2010 - A Beginner's Guide[^]

The debugger is here to show you what your code is doing and your task is to compare with what it should do.
When the code don't do what is expected, you are close to a bug.


Either this

gridview.rows[i].cells[0].getElementsByTagName("INPUT")[0]



is undefined\null, or "checkbox" is. Use the browser's debugger tools to examine the DOM to see what is in your DOM and why you can't find what you think is there. We don't have the rest of your page or your data so we can't do it for you, and you really need to learn to debug your code.


I also faced the same problem.
Problem is with for loop criteria
try this.
for(var i=1;i<gridview.rows.length-1;i++)>


这篇关于0x800a138f - javascript运行时错误:无法设置未定义或空引用的属性“已检查”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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