代码如下:
<html>
<head>
<script language=javascript>
function selectall(theform,thename){
var tform=document.forms[theform];
for(var i=0;i<tform.length;i++){
var e=tform.elements[i];
if(e.type=='checkbox' && e.id.indexof(thename)>=0)e.checked=!e.checked;
}
}
</script>
<meta http-equiv="Content-Language" content="zh-cn">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>张三 李辊 王五 刘国
何八 宁</title>
</head>
<body>
<form method="POST" action="--WEBBOT-SELF--" name="FrontPage_Form1">
<p><input type="checkbox" name="C1" id="人事部|正职" value="ON">张三
<input type="checkbox" name="C2" id="人事部|副职" value="ON">李辊
<input type="checkbox" name="C3" id="市场部|副职" value="ON">王五
<input type="checkbox" name="C4" id="市场部|正职" value="ON">刘国
<input type="checkbox" name="C5" id="技术部|正职" value="ON">何八
<input type="checkbox" name="C6" id="技术部|副职" value="ON">宁九</p>
<p>
<input name="thes0" type="button" onclick="javascript:selectall('FrontPage_Form1','人事部')" value="人事部" />
<input name="thes1" type="button" onclick="javascript:selectall('FrontPage_Form1','市场部')" value="市场部" />
<input name="thes2" type="button" onclick="javascript:selectall('FrontPage_Form1','技术部')" value="技术部" />
<input name="thes3" type="button" onclick="javascript:selectall('FrontPage_Form1','正职')" value="正职" />
<input name="thes4" type="button" onclick="javascript:selectall('FrontPage_Form1','副职')" value="副职" /></p>
</form>
</body>
</html>
目的是想按部门、职级来选择不同的人,但是运行时老时报错,我想是这句有问题:
if(e.type=='checkbox' && e.id.indexof(thename)>=0)e.checked=!e.checked;
但是自己刚学JS不久,不知道错在哪儿,请帮指点一下,谢谢!