关闭

分类全选 2006-6-9-2

502人阅读 评论(0) 收藏 举报

演示代码,只要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>

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:89522次
    • 积分:1497
    • 等级:
    • 排名:千里之外
    • 原创:53篇
    • 转载:17篇
    • 译文:0篇
    • 评论:11条
    文章分类