表格反选 Jquery实现

2018-05-10  本文已影响23人  ikaroskun

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方法

上一篇 下一篇

猜你喜欢

热点阅读