0
更新選擇選項時,我有一個形成兩個選擇:丟失後數據用jQuery
input_licensee_list
:充滿可能的選項(使用Ajax調用)output_licensee_list
:獲得來自用戶的選擇。
當我發表表格時,我收到了output_licensee_list
的列表。爲此,我添加了兩個按鈕:添加(將所選選項從輸入移動到輸出)和添加全部(將所有選項從輸入移動到輸出)。
// Add all button: remove all entries from input list and add them to output list
add_all_button.on('click', function (e) {
var options = input_licensee_list.find("option").remove();
options.append(' (' + group_selection.find("option:selected").text() + ')');
options.appendTo(output_licensee_list);
output_licensee_list.trigger('change');
input_licensee_list.trigger('change');
});
// Add button: remove selected entries from input list and add them to output list
add_button.on('click', function (e) {
var options = input_licensee_list.find("option:selected").remove();
options.append(' (' + group_selection.find("option:selected").text() + ')');
options.appendTo(output_licensee_list);
output_licensee_list.trigger('change');
input_licensee_list.trigger('change');
});
我準備了的jsfiddle顯示它:
https://jsfiddle.net/zaun8qgp/4/
jQuery代碼本身似乎做工精細,並且形式正確張貼,如果我使用「添加」按鈕(即使如果我選擇所有選項)。
但是出於某種原因,如果我使用「全部添加」按鈕:
- 輸入
output_licensee_list
沒有出現在POST可言,所以我沒有得到任何信息; - 如果我使用「添加」,然後「添加全部」,我在帖子中得到的信息,如果我最初添加的列表(在全部添加之前)。
如果任何人有線索爲什麼它不能正常工作,或者我可以如何調試更多,我將不勝感激!
太簡單了!謝謝,我可以找幾天... – Dric512