如何在Jquery Autocomplete combox中禁用特定选项 [英] How to disable a specific option in Jquery Autocomplete combox

查看:76
本文介绍了如何在Jquery Autocomplete combox中禁用特定选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我有简单的下拉框时

<select id="fruits">
<option value="apple">Apple</option>
<option value="orange">Orange</option>
<option value="banana" disabled="true">Banana</option>
</select>

香蕉选项在下拉列表中被禁用。

The Banana Option is disabled in the drop down.

当我尝试使用Jquery Autocomplete组合框时

When I tried to use Jquery Autocomplete Combo box

$( "#fruits" ).combobox();

自动完成下拉列表工作正常,但禁用选项Banana(已禁用选项集)。

The Autocomplete dropdown works fine, but the option Banana ( which has disabled option set ) is not disabled.

推荐答案

假设它是演示中的组合框
http://jqueryui.com/demos/autocomplete/

Assuming it's the combobox in the demo http://jqueryui.com/demos/autocomplete/

尝试替换此行:

response( select.children( "option" ).map(function() {

with:

response( select.children( "option" ).not(':disabled').map(function() {

你也可以使用优秀的选择元素格式化程序,它将搜索框与格式化相结合选择元素。

You could also use the excellent Chosen select element formatter which combines a search box with a formatted select element.

这篇关于如何在Jquery Autocomplete combox中禁用特定选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆