我有一个select div,我正在使用chosen jquery plugin来设置样式和添加功能(最显著的是搜索).这个部门看起来像这样,

 <select data-placeholder="add a foobar" id="foobar" style="width: 350px;">
 <option value=""></option>
 </select>

And I'm using the chosen plugin like this,

 $('#foobar').chosen();

While some AJAX is loading, I'd like to disable the entire <select> div. Maybe with something like this,

 $('#foobar').disable()

还是这个

 $('#foobar').prop('disabled', true)

我想你明白了.

Any ideas on how to do this? I've tried a number of different things, like using jquery idioms for disabling things, disabling the <select> which just disables the underlying select, not the chosen stuff on top of it. I've even resorted to manually adding another div with a high z-index to just grey out the box, but I think that this is likely to be ugly and buggy.

Thanks for the help!

推荐答案

You are disabling just your select, but chosen renders it as divs, and spans, etc. So after disabling your select you need to update the plugin to make the select widget disabled too. You can try this way:

$('#foobar').prop('disabled', true).trigger("liszt:updated");

//For non-older versions of chosen you would want to do:

$('#foobar').prop('disabled', true).trigger("chosen:updated");

我找到了here条信息

小提琴

Once you update the widget all it does is it unbinds the click or other events on the plugin and changes its opacity to 0.5. As there is no real disabled state for a div.

Jquery相关问答推荐

Django BaseDataTableView-Filter_queryset方法不起作用

如果选中了三个sibling ,则选中一个复选框

$(document).scrollTop() 总是返回 0

使用 jQuery 和 HTML 导出为 CSV

对混合的字母/数字数组进行排序

不使用插件的 jQuery 缓动函数

使用 jQuery 从 JavaScript 对象中添加/删除项目

将 CSS 应用于 jQuery 对话框按钮

页面重新加载后,如何使用 twitter bootstrap 保持当前选项卡处于活动状态?

使用 jQuery 将宽度设置为百分比

如何使用 jQuery 从 div 中删除 id 属性?

是否可以在 beforeunload 弹出窗口中显示自定义消息?

如何使用 jQuery 隐藏 div?

将片段添加到 URL 而不导致重定向?

jquery 检测某些类的 div 已添加到 DOM

表单 propType 失败:您在没有 `onChange` 处理程序的情况下向表单字段提供了 `value` props

在jQuery中,当它们都具有相同的名称时,如何获取单选按钮的值?

jQuery:通过 .attr() 添加两个属性;方法

使用 Chosen 插件更改 Select 中的 Select

使用 JQuery 判断组中是否没有选中单选按钮