jQuery Chosen插件动态添加选项 [英] jQuery Chosen plugin add options dynamically
问题描述
我制作一个 jQuery 这样的下拉菜单:
I make a jQuery Chosen drop-down like this:
$('.blah').chosen();
我找不到添加选项的方式,例如:
I can't find how I can add options, something like:
$('.blah').chosen('add', name, value);
推荐答案
首先,您需要将<option>
添加到选择绑定到的<select>
中.例如:
First, you need to add the <option>
s to the <select>
that Chosen was bound to. For example:
$('.blah').append('<option value="foo">Bar</option>');
然后,您需要触发chosen:updated
事件:
Then, you need to trigger the chosen:updated
event:
$('.blah').trigger("chosen:updated");
更多信息可以在此处中找到(尽管您需要向下滚动至Change / Update Events
).
More information can be found here (although you need to scroll down to Change / Update Events
).
2013年8月7日更新
Update 7th August 2013
正如Tony在评论中提到的那样,自1.0版(2013年7月)以来,事件名称已更改为chosen:updated
.可以在此处找到该文档.
The event name has changed to chosen:updated
since version 1.0 (July 2013) as Tony mentions in the comments. The updated documentation can be found here.
这篇关于jQuery Chosen插件动态添加选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!