var d=document.getElementsByTagName(CheckBoxName);
var k=[];
for (i=0;i<d.length;i++) {
d.onclick=function(){k[i]=this.checked==true?1:0;};
k[i]=0;
}上面是思路,没有测试,理论可行
var k=[];
for (i=0;i<d.length;i++) {
d.onclick=function(){k[i]=this.checked==true?1:0;};
k[i]=0;
}上面是思路,没有测试,理论可行
var k=[];
for (i=0;i<d.length;i++) {
d[i].onclick=function(){k[i]=this.checked==true?1:0;};
k[i]=0;
}
一个地方错了,改了
<HTML>
<Head>
<title> aaa </title>
<b>dsafsf</b><br>
<hr border = 2>
</head>
<script language = "javascript" >function clickcheck() {
var d=document.getElementsByTagName('checkb');
var k=[];
var str;
for (i=0;i<d.length;i++) {
d[i].onclick=function(){k[i]=this.checked==true?1:0;};
k[i]=0;
this.value = k[i];
}
}
</script>
<body onload = "selchg();">
<form name = "myform" method = "post">
<table backcolor = 0x0000ff border = 1>
<tr>
<td><input type = "checkbox" name = "checkb" value = "5">1</td>
</tr>
<tr>
<td><input type = "checkbox" name = "checkb" value = "6">2</td>
</tr>
<tr>
<td><input type = "checkbox" name = "checkb" value = "7">3</td>
</tr>
<tr>
<td><input type = "checkbox" name = "checkb" value = "8">4</td>
</tr>
</table>
</form>
<hr border = 2 color = 0xFF0000>
<form name = "myform2">
<input type = "text" name = "text1">
<input type = "button" name = "submit1" value = "submit1" onclick = "clickcheck();">
</form>
</body>
</HTML>
如:alert(k.join(','));我没测试啊,可能有些小错误的
<Head>
<title> aaa </title>
<b>dsafsf</b><br>
<hr border = 2>
</head>
<script language = "javascript" >
var k=[];
function clickcheck() {
var d=document.getElementsByName('checkb');
for (i=0;i<d.length;i++) {
eval("d[i].onclick=function(){k["+i+"]=this.checked==true?1:0;}");
k[i]=0;
this.value = k[i];
}
}
</script>
<body onload="clickcheck();">
<form name = "myform" method = "post">
<table backcolor = 0x0000ff border = 1>
<tr>
<td><input type = "checkbox" name = "checkb" value = "5">1</td>
</tr>
<tr>
<td><input type = "checkbox" name = "checkb" value = "6">2</td>
</tr>
<tr>
<td><input type = "checkbox" name = "checkb" value = "7">3</td>
</tr>
<tr>
<td><input type = "checkbox" name = "checkb" value = "8">4</td>
</tr>
</table>
</form>
<hr border = 2 color = 0xFF0000>
<form name = "myform2">
<p>
<input type = "text" name = "text1">
<input type = "button" name = "submit1" value = "submit1" onclick = "clickcheck();">
</p>
<p><a href="#" onClick="alert(k);return false;">test</a></p>
</form>
</body>
</HTML>我试了 可以 随手写的有点小错误 改过了
用户1 口
用户2 田
用户3 口
....
用户N 口还牵扯到了DB更新操作,只需要将页面上CheckBox发生变化的那些用户信息更新如DB,因此需要保存那些发生变化的用户,也就有了上面的问题。