Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/87.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
Javascript 轻松地限制选中的复选框jqueryui_Javascript_Jquery_Checkbox - Fatal编程技术网

Javascript 轻松地限制选中的复选框jqueryui

Javascript 轻松地限制选中的复选框jqueryui,javascript,jquery,checkbox,Javascript,Jquery,Checkbox,只是想限制复选框的数量,但实际上我的代码在长度>3时不允许所有复选框,这有什么不对 问候 Jess('.limit:checkbox')。removeAttr('checked')是错误的。它将取消选中所有复选框 也许您的意思是$(this).removeAttr('checked')(但是您已经有this.checked=false)?只需删除removeAttr('checked') 将选中的设置为false,然后调用按钮(“刷新”): 试着这样做: $(function () {

只是想限制复选框的数量,但实际上我的代码在长度>3时不允许所有复选框,这有什么不对

问候 Jess('.limit:checkbox')。removeAttr('checked')是错误的。它将取消选中所有复选框


也许您的意思是
$(this).removeAttr('checked')
(但是您已经有
this.checked=false
)?

只需删除
removeAttr('checked')


将选中的设置为
false
,然后调用
按钮(“刷新”)

试着这样做:

$(function () {
    $(".limit").buttonset();

    var max = 3;
    var checkboxes = $('input[type="checkbox"]', '.limit');

    checkboxes.change(function () {
        var current = checkboxes.filter(':checked').length;
        checkboxes.filter(':not(:checked)').prop('disabled', current >= max).button('refresh');
    });
});

演示:

没有,我尝试过,但由于一些未知原因,您无法使用此方法取消选中所有复选框,请尝试。没有问题,pb是一些使用这些按钮的陈词滥调。。不知道为什么,我想这是最后一个按钮不能打开,但它可以,困难的点击..你知道为什么吗?!
$(function() {
    $(".limit").buttonset();
    $('.limit :checkbox').change(function () {
        var $cs=$(this).closest('.limit').find(':checkbox:checked');
        if ($cs.length > 3) {
            this.checked=false;
            $('.limit :checkbox').button( "refresh" );
        }
    });
});
$(this).prop('checked', false).button('refresh');
$(function () {
    $(".limit").buttonset();

    var max = 3;
    var checkboxes = $('input[type="checkbox"]', '.limit');

    checkboxes.change(function () {
        var current = checkboxes.filter(':checked').length;
        checkboxes.filter(':not(:checked)').prop('disabled', current >= max).button('refresh');
    });
});