jQuery   发布时间:2022-03-30  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了Jquery选择表中的所有复选框大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个脚本,应该检查表中的所有复选框.它首次检查它们,之后它会取消选中它们.但是,当我尝试重新检查它们什么也没有发生.

jquery

$('#SELEctAll').click(function(E){
    var table= $(e.target).closest('table');
    $('td input:checkBox',tablE).attr('checked',e.target.checked);
});

HTML:

<table>
    <tr>
        <th>
            <input type="checkBox" id="SELEctAll" />
        </th>
        <th>
            hi!
        </th>
    </tr>
    <tr>
        <td>
            <input type="checkBox" id="1"/>
        </td>
        <td>
            hi!
        </td>
    </tr>
    <tr>
        <td>
            <input type="checkBox" id="2"/>
        </td>
        <td>
            hi!
        </td>
    </tr>
</table>

这是一个行为的小提琴:

http://jsfiddle.net/EEJrU/

为什么点击一次后不起作用?

解决方法

您需要使用 .prop()而不是 .attr()
$('#SELEctAll').click(function(E){
    var table= $(e.target).closest('table');
    $('td input:checkBox',tablE).prop('checked',this.checked);
});

演示:Fiddle

Attributes vs. Properties

大佬总结

以上是大佬教程为你收集整理的Jquery选择表中的所有复选框全部内容,希望文章能够帮你解决Jquery选择表中的所有复选框所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。