分类全选 2006-6-9-2

演示代码,只要checkbox的name一样且在一个表单里就可以

调用时用checkall(this,'checkboxname')就可以

代码如下

<script language=Javascript>
function checkall(all,checkname)//用于判断全选记录的函数
{
var a = document.getElementsByName(checkname);
for (var i=0; i<a.length; i++) a[i].checked = all.checked;
}
</script>

<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td width="29%" height="162"><table width="100%" border="0" cellspacing="0" cellpadding="0">
        <form method="POST" id=form1 name=form1>
          <tr>
            <td><input type="checkbox" name="answer" value="1">
              answer1</td>
          </tr>
          <tr>
            <td><input type="checkbox" name="answer" value="2">
              answer2</td>
          </tr>
          <tr>
            <td><input type="checkbox" name="answer" value="3">
              answer3</td>
          </tr>
          <tr>
            <td><input type="checkbox" name="answer" value="4">
              answer4</td>
          </tr>
          <tr>
            <td><input type="checkbox" name="answer" value="5">
              answer5</td>
          </tr>
          <tr>
            <td><input type="checkbox" name="chkall" value="on" onClick="checkall(this,'answer')">
              选中所有answer</td>
          </tr>
          <tr>
            <td>&nbsp;</td>
          </tr>
        </form>
      </table></td>
    <td width="71%"><table width="100%" border="0" cellspacing="0" cellpadding="0">
        <form method="POST" id=form1 name=form1>
          <tr>
            <td><input type="checkbox" name="question" value="1">
              question1</td>
          </tr>
          <tr>
            <td><input type="checkbox" name="question" value="2">
              question2</td>
          </tr>
          <tr>
            <td><input type="checkbox" name="question" value="3">
              question3</td>
          </tr>
          <tr>
            <td><input type="checkbox" name="question" value="4">
              question4</td>
          </tr>
          <tr>
            <td><input type="checkbox" name="question" value="5">
              question5</td>
          </tr>
          <tr>
            <td><input type="checkbox" name="chkall" value="on" onClick="checkall(this,'question')">
              选中所有question</td>
          </tr>
          <tr>
            <td>&nbsp;</td>
          </tr>
        </form>
      </table></td>
  </tr>
</table>

阅读更多
个人分类: Javascript
想对作者说点什么? 我来说一句

全选js.txt

2011年06月22日 990B 下载

没有更多推荐了,返回首页

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭