天天看点

js 获取checkbox选中项目

#

//获取选中项
$('#submit').click(function () {
    var check_list = []
    $("input[name='ck']:checked").each(function () {
        check_list.push(this.value);
    });
    alert(check_list.join(","));
});

//全选/取消全选
$('#all').toggle(function () {
    $("input[name='ck']").attr("checked", 'true');
}, function () {
    $("input[name='ck']").removeAttr("checked");
});


//反选
$('#unselected').click(function () {
    $("input[name='ck']").each(function () {
        if ($(this).attr("checked")) {
            $(this).removeAttr("checked");
        } else {
            $(this).attr("checked", 'true');
        }
    });
});

      

#

转载于:https://www.cnblogs.com/weiok/p/5118482.html