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;
}上面是思路,没有测试,理论可行

解决方案 »

  1.   

    var d=document.getElementsByTagName(CheckBoxName);
    var k=[];
    for (i=0;i<d.length;i++) {
    d[i].onclick=function(){k[i]=this.checked==true?1:0;};
    k[i]=0;
    }
    一个地方错了,改了
      

  2.   

    我在HTML中如何触发这段代码阿 请赐教。
      

  3.   

    我的代码如下,不知道什么地方出错了:
    <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>
      

  4.   

    不用触发 页面载入后初始化所有相同名字的CHECKBOX增加onclick事件之后随时可以察看保存在数组k里的状态。
    如:alert(k.join(','));我没测试啊,可能有些小错误的
      

  5.   

    <HTML>
    <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>我试了 可以 随手写的有点小错误 改过了
      

  6.   

    点击test连接,可以弹出Message,但是代码看不懂没有深入学习过HTMLfunction clickcheck() {...} 的内容,是何时被调用的呢
      

  7.   

    非常感谢,我在用JSP 做一个项目,页面上可以通过这样的方式,来给用户赋予或者删除权限。
        用户1        口      
        用户2        田
        用户3        口
        ....
        用户N        口还牵扯到了DB更新操作,只需要将页面上CheckBox发生变化的那些用户信息更新如DB,因此需要保存那些发生变化的用户,也就有了上面的问题。