小编glu*_*ree的帖子

使用Jquery检查和取消选中输入只能工作一次

我试图通过单击表头中的一个复选框来选中/取消选中所有复选框.首先单击add attributes to inputs,然后取消选中.它只工作一次.在Firefox和Chrome上测试.Аttributes不断变化,但这不会显示在页面中.我只在浏览器调试器中看到它.

<table>
    <thead>
        <tr>
            <th><input type="checkbox" /></th>
            <th>#</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td><input type="checkbox" /></td>
            <td>1</td>
        </tr>
        <tr>
            <td><input type="checkbox" /></td>
            <td>2</td>
        </tr>
        <tr>
            <td><input type="checkbox" /></td>
            <td>3</td>
        </tr>
    </tbody>
</table>

<script type="text/javascript">
$(function () {
    $('th input[type="checkbox"]').click(function(){
        if ( $(this).is(':checked') )
            $('td input[type="checkbox"]').attr('checked', 'checked');
        else
            // $('td input[type="checkbox"]').attr('checked', false);
            $('td input[type="checkbox"]').removeAttr('checked');
    })
});
</script>
Run Code Online (Sandbox Code Playgroud)

示例 http://jsfiddle.net/aJhm9/

checkbox jquery

5
推荐指数
1
解决办法
6602
查看次数

标签 统计

checkbox ×1

jquery ×1