1. 程式人生 > >js點擊行選中checkbox

js點擊行選中checkbox

top col turn nbsp check list not input 事件冒泡

1、點擊行選中checkbox復選框

//點擊行勾選
$("#Qub_tb_List").on("click", "tr", function () {
    var input = $(this).find("input");
    if ($(input).val() == "on") {
        return;
    }
    $("#Qub_tb_List *").not(input).prop("checked", false);  //點擊行,只能選擇一行
    if (!$(input).prop("checked")) {
        $(input).prop(
"checked", true); } else { $(input).prop("checked", false); } });

2、全選功能

//多選框 防止事件冒泡
$("#Qub_tb_List").on("click", "input", function (event) {
    event.stopImmediatePropagation();
});

//全選功能
$("input[name=‘all_check‘]").change(function () {
   if (this.checked) {
    $("input[name=‘check_tr‘]:checkbox
").each(function () { this.checked = true; }) } else { $("input[name=‘check_tr‘]:checkbox").each(function () { this.checked = false; }) } });

js點擊行選中checkbox