允许使用selected.js多重选择的新值 [英] allow new values with chosen.js multiple select
问题描述
我正在使用selected.js插件 http://harvesthq.github.com/chosen/与jQuery一起使用,以允许用户从一个选择中选择多个选项.但是,我现在希望能够让它们创建尚不存在的值-知道如何解决这个问题吗?
I'm using the chosen.js plugin http://harvesthq.github.com/chosen/ with jQuery to allow the user to select multiple options from a select. However, I now want to be able to let them create values that aren't already present - any idea how to go about this?
类似于SO自己的标签选择/创建栏的内容将接近我想要的内容
something similar to SO's own tag selection/creation bar would be close to what I'm after
最好不更改或编辑插件,但会在需要时这样做.
Preferably without changing or editing the plugin, but will do if required.
代码: HTML:
<p>Select something</p>
<select name="theSelect[]" multiple="multiple">
<option value="First Option">First Option</option>
<option value="Second Option">Second Option</option>
</select>
JavaScript:
Javascript:
$(function(){
$('select').chosen();
});
因此,如果用户键入第三选项",我想将其添加到列表中并选择它.值和显示名称是/相同,所以不必担心
So if a user were to type in "Third Option", i'd like to add that to the list and have it selected. The value and display name are / will be the same so that's not a concern
推荐答案
根据文档,您可以尝试执行以下操作:
According to the documentation you can try doing something like this:
$('select').append('<option>test</option>');
$('select').trigger('liszt:updated');
如Tony在以下评论中所述:
As Tony stated in the comments below:
从1.0版开始,现在已选择:更新触发器".请参见 harvesthq.github.io /chosen/#change-update-events "
"Starting with version 1.0 which the trigger is now "chosen:updated". See harvesthq.github.io/chosen/#change-update-events"
这篇关于允许使用selected.js多重选择的新值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!