常用

1、复选框的全选、全不选

//-------------------------------------所有页面的全选/全不选-----------------------
$("#searchresulttable").on("change",".checkall",function(){
    if($(this).is(":checked")){
        var $allcheckbox =$(this).parents("thead").next().find("input:checkbox");
        $allcheckbox.each(function(){
            //console.log($(this).val())
            $(this).prop("checked",true);
        });
    }else{
        $(this).parents("thead").next().find("input:checkbox").each(function(){
            //console.log($(this).val())
            $(this).prop("checked",false);
        });
    }
})
$("#searchresulttable").on("click","input:checkbox",function(){
    if($(this).prop("checked")==false){
        $(this).parents("table").find("thead input:checkbox").prop("checked",false);
    }else{
        $(this).parents("table").find(".checkall")
            .prop("checked",$(this).parents("tbody").find("input:checkbox").length == $(this).parents("tbody").find("input:checkbox:checked").length?true:false )
    }
});

  2、最多选择5个

$("#workFunction").on("click",'input[type=checkbox][name=fb]',function() {
    $("#workFunction").find("input[type=checkbox][name=fb]").attr('disabled', true);
    if ($("#workFunction").find("input[type=checkbox][name=fb]:checked").length >= 5) {
        $("#workFunction").find("input[type=checkbox][name=fb]:checked").attr('disabled', false);
    } else {
        $("#workFunction").find("input[type=checkbox][name=fb]").attr('disabled', false);
    }
    var str="";
    $("#workFunction").find("input[type=checkbox][name=fb]:checked").each(function () {
        str += (str==""?"":",")+$(this).attr("value");
    })
    $("#expectedFunctions").val(str);
});

 

posted @ 2017-10-24 13:56  Eva3288  阅读(195)  评论(0)    收藏  举报