如何使用MultiSelect jQuery插件添加选项 [英] How to add option using MultiSelect jQuery plugin
问题描述
我正在使用jQuery-MultiSelect插件.
I am using the jQuery - MultiSelect plugin.
我希望能够在我的初始选择框中添加一个选项,然后用新选项更新MultiSelect用户界面.
I want to be able to add an option to my initial select box, and then have the MultiSelect user interface update with the new option.
这是我所拥有的(不起作用).
Here is what I have (which doesn't work).
var value = $("#newGroup").val();
$('#Select1').append("<option value=\"" + value + "\">" + value + "</option>");
然后,我尝试调用相同的代码来重新创建多重选择以及其他选项,例如首先销毁它.
Then I've tried to call the same code to recreate the multiselect along with other options like destroying it first.
这是我用来实现插件的代码.
Here is the code I use to implement the plugin.
$("#Select1").multiselect({ sortable: false, searchable: true });
这是插件的主页: http://quasipartikel.at/multiselect_next/
推荐答案
您是否拥有MultiSelect的最新版本?现在,版本1.8添加了一个刷新命令,该命令旨在更新列表以反映新添加或删除的选项.您的代码序列应为:
Do you have the latest version of MultiSelect? Version 1.8 now adds a refresh command that is designed to update lists to reflect newly appended or deleted options. Your code sequence should be:
var value = $("#newGroup").val();
$('#Select1').append("<option value=\"" + value + "\">" + value + "</option>");
$('#Select1').multiselect( 'refresh' );
这篇关于如何使用MultiSelect jQuery插件添加选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!