I have a si开发者_如何学编程mple 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
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. Use children
or getElementsByTagName
instead:
The following assumes that there is an element before the <input>
:
cell.children[1].checked = document.getElementById(id).checked;
精彩评论