有人可以帮助我解决这个问题
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代码:
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>"
这是我的选择框:
response.Write "<th align=left><input type=checkbox onclick=CheckAll(this)></th>"
当我点击全选框时,我如何选择这些框(似乎功能不起作用) 请帮助我,而不是给我这个例子...非常感谢你帮助〜
更新:
我是指Roland的建议并制作新功能,但是没有任何想法?
功能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;
}
}
}
答案 0 :(得分:1)
您可以选择并选中所有复选框:
首先找到你的元素(这是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;
};
然后,您可以使用此“实用程序”功能检查所有内容:
var checkAll = function() {
var checkBoxes = find("process");
for(var i = 0; i < checkBoxes.length; i++) {
checkBoxes[i].checked = true;
}
}
这是一个小提琴:
作为旁注,这里的这个位不是有效的html(你错过了一些引号):
response.Write "<td nowrap><input type=checkbox name=process_1 "
response.Write "/>box1</td>"
我相信它需要:
response.Write "<td nowrap><input type='checkbox' name='process_1' "
response.Write "/>box1</td>"