[英]Type Error: getElementById..null with h:selectBooleanCheckbox
The code is working and setting the values with 代码正在工作,并使用
setCookie('newWindow', document.getElementById("myForm:header:"+1+":chekDeleted").checked? 1:0,100);
but when i call the getElementById in loop it says type error 但是当我在循环中调用getElementById时,它说类型错误
var count = 0;
for(i=1;i<totalRecords;i++)
{
var chkBox = getElementById("myForm:header:"+i+":chekDeleted");
if(chkBox.checked == true)
{
count++;
if(count > 1)
{
setCookie('newWindow', document.getElementById("myForm:header:"+i+":chekDeleted").checked? 1:0,100);
}
}
}
Try to add document.
尝试添加
document.
: :
for(i=1;i<totalRecords;i++)
{
var chkBox = document.getElementById("myForm:header:"+i+":chekDeleted");
if(chkBox.checked == true)
{
count++;
if(count > 1)
{
setCookie('newWindow', document.getElementById("myForm:header:"+i+":chekDeleted").checked? 1:0,100);
}
}
}
If you still having the error, it is because the element with those ids are not loaded. 如果仍然出现错误,那是因为未加载具有这些ID的元素。 in that case,
chkBox
returns null
and if(chkBox.checked == true)
returns error Uncaught TypeError: Cannot read property 'checked' of null 在这种情况下,
chkBox
返回null
而if(chkBox.checked == true)
返回错误Uncaught TypeError:无法读取null的'checked'属性
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.