1. 程式人生 > >監聽復選框

監聽復選框

hidden nts tab nbsp hid his div chang ()

1.全部選中按鈕

    /*全部選中*/
    $("body").on("click","#all-check",function(){
        var button = $(this);
        var input = $(".layui-table").find("input");
        if(input.is(":checked")){
            input.each(function(){
                this.checked=false;
            }).change()
            button.text(
"全部選中"); }else{ input.each(function(){ this.checked=true; }).change() button.text("全部取消"); } });

2.監聽復選框

    $("body").on("change",".layui-table input",function(){
        var id = $(this).parents("tr").attr("data-id");
        
if($(this).is(":checked")){ $("#hidden").append(id+","); }else{ var text = $.trim($("#hidden").text()); var str = $.trim(text.replace(id+",","")); $("#hidden").html(str); } });

監聽復選框