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');
        }
    });
});

#

posted @ 2016-01-10 15:06  weiokx  阅读(661)  评论(0编辑  收藏  举报