使用复选框启用/禁用选择器(没有单独的按钮,没有“ if”)

我有这种多行形式,其中元素之一是selectpicker()。在每一行的前面,都有一个复选框:选中后,它会删除每个输入的disabled="disabled"属性并进行选择。但是它对于选择器无效。

我已经检查了文档–“刷新”示例,其中使用两个单独的按钮启用/禁用了下拉菜单,但对我而言这是没有用的。我似乎不太了解如何根据自己的需要对此进行自定义。

这是我用来启用/禁用其余输入/选择的jQuery代码:

$('input.activate[type="checkbox"]').on('change',function() {
    $(this).closest('.tablerow').find('input[type="text"]').prop('disabled',!this.checked);
    $(this).closest('.tablerow').find('select').prop('disabled',!this.checked);
    $(this).closest('.tablerow').find('input[type="hidden"]').prop('disabled',!this.checked);
});

我尝试添加:

$(this).closest('.tablerow').find('button').prop('aria-disabled',!this.checked);

因为我可以看到aria-disabled="true"被添加到了覆盖select标签的按钮上,但这没用。

以下方法也不起作用(用引号{true/false和不引号):

var buttondrop = $(this).closest('.tablerow').find('button');
if($('input.activate[type="checkbox"]').is(':checked')) {
    buttondrop.prop('aria-disabled','true');
    $('.disable-example').selectpicker('refresh');
}
else {
    buttondrop.prop('aria-disabled','false');
    $('.disable-example').selectpicker('refresh');
}

已解决! –部分: 我遗漏了一些显而易见的东西–我还需要从按钮中删除并添加disabled CSS类。因此此代码有效。

var buttondrop = $(this).closest('.tablerow').find('button');
if($('input.activate[type="checkbox"]').is(':checked')) {
    buttondrop.prop('aria-disabled',true).removeclass('disabled');
    $('.disable-example').selectpicker('refresh');
}
else {
    buttondrop.prop('aria-disabled',false).addClass('disabled');
    $('.disable-example').selectpicker('refresh');
}

但是,我非常希望能够像其他表单元素一样在一行中完成 。需要具备jQuery专业知识的人,请帮助。

sytsoft 回答:使用复选框启用/禁用选择器(没有单独的按钮,没有“ if”)

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3084587.html

大家都在问