Internet Explorer JavaScript 兼容性
我有一个简单的 javascript 函数,可以在选择标题复选框时检查所有复选框。
function SelectAll(id) {
var grid = document.getElementById("<%=ui_downlinkGrid.ClientID %>");
var cell;
if (grid.rows.length > 0)
{
for (i = 0; i < grid.rows.length; i++)
{
cell = grid.rows[i].cells[0];
cell.childNodes[1].checked = document.getElementById(id).checked;
}
}
}
我在 IE 9 上进行了测试,效果非常好。然而,一旦我在 Windows Server 2008 上得到它,它就不起作用,并且调试器显示此错误:对象不支持此属性或方法。
这是兼容性问题吗?我该如何解决这个问题?
编辑:错误在此行:
cell.childNodes[1].checked = document.getElementById(id).checked
I have a simple javascript function to check all checkboxes when a header checkbox is selected.
function SelectAll(id) {
var grid = document.getElementById("<%=ui_downlinkGrid.ClientID %>");
var cell;
if (grid.rows.length > 0)
{
for (i = 0; i < grid.rows.length; i++)
{
cell = grid.rows[i].cells[0];
cell.childNodes[1].checked = document.getElementById(id).checked;
}
}
}
I tested this on IE 9 and it works perfectly. However once I got it on Windows Server 2008, it does not work, and the debugger shows this error: Object doesn't support this property or method.
Is this a compatibility issue? How can I solve this?
EDIT: The error is on this line:
cell.childNodes[1].checked = document.getElementById(id).checked
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
childNodes
返回文本节点和元素,您现在可能正在点击文本节点,而不是您尝试访问的输入。请改用children
或getElementsByTagName
:以下假设
之前有一个元素:
childNodes
return text nodes as well as elements, its plausible that you are now hitting a textnode, rather than the input you are attempting to access. Usechildren
orgetElementsByTagName
instead:The following assumes that there is an element before the
<input>
: