2016-07-14 30 views
0

複数のドロップダウンボックスにチェックボックスを付けると疑いがあります。私は動的にjquery.Howで新しいデータでドロップダウンをリフレッシュするには、画像をアップロードするたびにドロップダウンでコンテンツを追加したいですか?jquery内の複数選択ドロップダウンメニューにコンテンツを動的に追加します

$('#listImage').multiselect({}); 

一度私は新しいデータを取得します。私はマルチ選択をリフレッシュしようとしましたが、それはエラーをスローします。

$("#widgetSettingsForm select[multiple]").multiselect('rebuild'); 

不明なエラー:いいえ、そのようなメソッド(...)複数選択ウィジェットのインスタンスに対して '再構築'

答えて

2

使用してリフレッシュする代わりの再構築:http://jsfiddle.net/o7xf9awv/1/

$("#test001").multiselect('refresh'); 

$("#test001").multiselect({ 
 
    header: false, 
 
    noneSelectedText: "Select" 
 
}); 
 
var count = 2; 
 
$("#add").click(function() { 
 
    $("#test001").append('<option value="option5">Option ' + ++count + '</option>'); 
 
    $("#test001").multiselect('refresh'); 
 
}); 
 

 
$("#remove").click(function() { 
 
    $("#test001 option:last").remove(); 
 
    $("#test001").multiselect('refresh'); 
 
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script> 
 
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.13/jquery-ui.min.js"></script> 
 
<script src="https://raw.githubusercontent.com/ehynds/jquery-ui-multiselect-widget/1.10/src/jquery.multiselect.min.js"></script> 
 
<link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.13/themes/redmond/jquery-ui.css"> 
 
<link rel="stylesheet" type="text/css" href="https://raw.githubusercontent.com/ehynds/jquery-ui-multiselect-widget/1.10/jquery.multiselect.css"> 
 
<input type="button" id="add" value="add" /> 
 
<input type="button" id="remove" value="remove last" /> 
 
<br/> 
 
<select id="test001" multiple="multiple"> 
 
    <option value="option1">Option 1</option> 
 
    <option value="option2">Option 2</option> 
 
</select>

+0

何かを動的に削除するには? – Kallis

+0

更新されたコードを確認してください。あなたは同じ行にあなたのカスタム削除を書くことができます。 –

関連する問題