+ -
当前位置:首页 → 问答吧 → 求助:jquery中复选框的相关操作(急)

求助:jquery中复选框的相关操作(急)

时间:2009-06-26

来源:互联网

如何用jquery实现如下功能:实现selectAll()函数,当把name="all" id="all" 对应的复选框选中时(checked="checked"),使表单中所有type="checkbox" name="checkbox"的复选框都选中,反之都不选中。

相关的代码如下:
<form id="form" name="form" method="post" action="">
  <table width="200" border="1">
    <tr>
      <td>
        <input type="checkbox" name="all" id="all" onclick="selectAll()" />
        <input type="button"  value="全删" />
      </td>
    </tr>
    <tr>
      <td>
        <input type="checkbox" name="checkbox"/>    
        <input type="button" value="删除" />
      </td>
    </tr>
    <tr>
      <td>
        <input type="checkbox" name="checkbox" />     
        <input type="button" value="删除" />
        </td>
    </tr>
    <tr>
      <td>
        <input type="checkbox" name="checkbox"/>   
        <input type="button" value="删除" />
       </td>
    </tr>
  </table>
</form>

作者: myeclipse10   发布时间: 2009-06-26

<script type="text/javascript">
    $(document).ready(function() {
        $("#all").click(function() {
            var r=$("input[type=checkbox]").not($(this)).attr("checked",this.checked);
            
        });
    });
</script>

作者: 大海   发布时间: 2009-06-26