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