function checkUncheckAll(theElement) {
var theForm = theElement.form, z = 0;
while (theForm[z].type == 'checkbox' && theForm[z].name != 'checkall') {
theForm[z].checked = theElement.checked;
z++;
}
}
Run Code Online (Sandbox Code Playgroud)
theElement是复选框列表底部的checkall复选框.单击时,它调用此函数将所有复选框以相同的形式设置为checkall的值.
除了IE中的一个小故障外,它适用于所有浏览器.单击checkall框后,似乎复选框已更新,但您没有看到它.如果单击页面上的任意位置,则复选框将更新为其正确状态.检查和取消检查都会发生这种情况.