2016-07-29 62 views
0

該列表可以很容易地排序,所以我想要類似的地方,其中<select>標籤的選項可以根據我的需要進行排列,同時仍保留<select>標籤的原始功能。是否有可能使用jquery排序單選?

是否有可能使用jquery排序重新排列<options><select>

+0

有些事情你有沒有看着結合的jQuery UI的選擇和排序? – epascarello

+0

可選擇的所有文檔也使用ul li,並且將我帶回原始問題 –

+0

因此,將其轉換爲該格式,使用JavaScript並不困難。您不能拖放選項元素。 – epascarello

回答

-1

這樣

var options = $("#select option");  
options.sort(function(a,b) { 
    if (a.text > b.text) return 1; 
    if (a.text < b.text) return -1; 
    return 0 
}) 

$("#select").empty().append(options); 
$("#select").val(""); 
相關問題