[英]Function didn't work with document.all
Can someone help me to solve this problem 有人可以帮我解决这个问题吗
Javascript Code: JavaScript代码:
function CheckAll(pObj) {
var mCurrStatus;
mCurrStatus = pObj.checked;
var mObjList; mObjList = document.all["process"];
for (x = 0; x <= 2; x++) {
var Obj;
Obj = mObjList[x];
Obj.checked = mCurrStatus;
}
}
asp-classic code: ASP经典代码:
response.Write "<td nowrap><input type=checkbox name=process_1 "
response.Write "/>box1</td>"
response.Write "<td nowrap><input type=checkbox name=process_2 "
response.Write "/>box2</td>"
and this is my selectall box : 这是我的全选框:
response.Write "<th align=left><input type=checkbox onclick=CheckAll(this)></th>"
how do i select thoses boxes when i click the select all box (it's seem the function doesn't work) please help me instead of giving me the example... thanks so much for you guy help~ 单击全选框时,如何选择那些框(似乎功能不起作用),请帮我,而不是举个例子...非常感谢您的帮助〜
Updated: 更新:
i refer to Roland suggestion and make the new function but doesn't work any idea? 我参考Roland的建议并做了新的功能,但不起作用吗?
function CheckAll() { 函数CheckAll(){
var eles = [];
var len = elems.length;
//var inputs = document.getElementsByTagName("input");
var elems = tab.getElementsByTagName("input");
for (var i = 0; i < len; i++) {
if (elems[i].name.indexOf('process_') == 0) {
eles.push(elems[i]);
}
}
//var elems = tab.getElementsByTagName("input");
for (var x = 0; x < len; x++) {
if (elems[x].type == "checkbox") {
elems[x].checked = true;
}
}
} }
This is how you can select and check all the checkboxes: 这是您可以选择并选中所有复选框的方式:
First find your elements (this is vanilla.js): 首先找到您的元素(这是vanilla.js):
// will find all the html elements that have a name containing the value passed
var find = function(name) {
// you can optimize this part a bit (pass the tag name)
var elements = document.getElementsByTagName("*");
var results = [];
for(var i = 0; i < elements.length; i++) {
var elementName = elements[i].name;
if(elementName !== undefined && elementName.indexOf(name) != -1) {
results.push(elements[i]);
}
}
return results;
};
Then this is how you use this "utility" function to check all: 然后,这就是您使用此“实用程序”功能检查所有内容的方式:
var checkAll = function() {
var checkBoxes = find("process");
for(var i = 0; i < checkBoxes.length; i++) {
checkBoxes[i].checked = true;
}
}
Here is a fiddle: 这是一个小提琴:
http://jsfiddle.net/BuacB/1/ http://jsfiddle.net/BuacB/1/
As a side note, this bit here is not valid html (you're missing some quotes): 顺便说一句,这是无效的html(您缺少一些引号):
response.Write "<td nowrap><input type=checkbox name=process_1 "
response.Write "/>box1</td>"
I beleive it needs to be: 我相信它必须是:
response.Write "<td nowrap><input type='checkbox' name='process_1' "
response.Write "/>box1</td>"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.