我創建腳本,它發送AJAX請求和刷新選擇與選項元素的列表元素。有人做過之後,我嘗試使用JQuery plugin jQuery.sortElements.js選項元素進行排序:JQuery的種類只有斷點在Firebug存在
/* If region is specified */
if (regionId != '0') {
/* AJAX request to get city list and refresh select state. */
$.getJSON('/json/cities', {region_id: regionId}, function(json) {
$("select.changedBy-" + regionSelectId).each(function() {
var citySelect = $(this);
$.each(json, function(id, name) {
$('<option value="' + id + '">' + name + '</option>').appendTo(citySelect);
});
});
});
/* Sorting */
$("select.changedBy-" + regionSelectId).each(function() {
$(this).find('option').sortElements(function(option1, option2) {
var option1Value = $(option1).attr('value');
var option2Value = $(option2).attr('value');
if (option1Value == '0') return -1;
if (option2Value == '0') return 1;
if (option1Value == regionId) return -1;
if (option2Value == regionId) return 1;
return $(option1).text() > $(option2).text() ? 1 : -1;
});
});
}
};
不幸的是,整理作品只有當我把斷點在Firebug在下面一行:
$("select.changedBy-" + regionSelectId).each(function() {
在其他情況下(常規模式)它不排序選項元素。你能幫我找到這個問題的原因嗎?
謝謝, 鮑里斯。