美文网首页
表格反选 Jquery实现

表格反选 Jquery实现

作者: ikaroskun | 来源:发表于2018-05-10 17:04 被阅读23次

JS 函数如下:

function invertSelect() {
    $("INPUT[type='checkbox']").each(function () {
        if ($(this).prop('checked')) {
            $(this).prop('checked', false);
            $(this).parents('.checkbox').find('span').removeClass('checked');
        } else {
            $(this).prop('checked', true);
            // $(this).parents('.checkbox').find('span').addClass('checked');
            $(this).parent("span").addClass("checked");
        }
    });
}

之前有看到设置值是用attr方法,新版本之后不生效,需要使用prop方法

相关文章

网友评论

      本文标题:表格反选 Jquery实现

      本文链接:https://www.haomeiwen.com/subject/rmhtdftx.html