Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/76.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使函数选择所有jquery_Jquery_Checkbox_Selectall - Fatal编程技术网

使函数选择所有jquery

使函数选择所有jquery,jquery,checkbox,selectall,Jquery,Checkbox,Selectall,我有一个全选jquery脚本,我是从一个我忘记链接的网站上得到的。。没错,剧本没什么问题。它起作用了。但是,我打算把它重写成一个函数。只是,我累坏了 这是ori脚本 $("#selectall").click(function () { $('.case').attr('checked', this.checked); }); $(".case").click(function(){ if($(".case").length == $(".case:checked")

我有一个全选jquery脚本,我是从一个我忘记链接的网站上得到的。。没错,剧本没什么问题。它起作用了。但是,我打算把它重写成一个函数。只是,我累坏了

这是ori脚本

    $("#selectall").click(function () {
     $('.case').attr('checked', this.checked);
});

$(".case").click(function(){
    if($(".case").length == $(".case:checked").length) {
        $("#selectall").attr("checked", "checked");
    } else {
        $("#selectall").removeAttr("checked");
    }
});
以下是我编写的函数:

function klikAll(id){
   var header = $('#' + id);
   $('.foo_' + hid).attr('checked', header.prop('checked') );
}

function klikSub(hid){
   var heder = $('#' + hid);
   var subheder = $('.foo_' + hid);
   var subhederc = $('.foo_' + hid + ':checked');

   if(subheder.length == subhederc.length) {
      heder.attr("checked", "checked");
   } else {
      heder.removeAttr("checked");
   }
}
问题是,该功能完全不起作用。。在JSFIDLE中,我重写了它。谁能给我一个线索,我应该在哪一部分修好?或者我的功能有什么问题???

请检查此项

代码


将你的函数放在块中。

哦,我的天哪!我不相信:3非常感谢@thecode悖论:D它解决了我的痛苦
<script type="text/javascript">
function klikAll(id) {
    var header = $('#' + id);
    $('.foo_' + id).attr('checked', header.prop('checked'));
}

function klikSub(hid) {
    var heder = $('#' + hid);
    var subheder = $('.foo_' + hid);
    var subhederc = $('.foo_' + hid + ':checked');

    if (subheder.length == subhederc.length) {
        heder.attr("checked", "checked");
    } else {
        heder.removeAttr("checked");
    }
}
</script>