Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/429.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jquery-ui/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 排序下拉列表后选择出错_Javascript_Jquery_Html_Sorting_Drop Down Menu - Fatal编程技术网

Javascript 排序下拉列表后选择出错

Javascript 排序下拉列表后选择出错,javascript,jquery,html,sorting,drop-down-menu,Javascript,Jquery,Html,Sorting,Drop Down Menu,我已使用此功能对下拉列表进行排序: function SortOptions(id) { var prePrepend = "#"; if (id.match("^#") == "#") prePrepend = ""; $(prePrepend + id).html($(prePrepend + id + " option").sort( function (a, b) { return a.text == b.text ? 0 : a.text <

我已使用此功能对下拉列表进行排序:

function SortOptions(id) {
    var prePrepend = "#";
    if (id.match("^#") == "#") prePrepend = "";
    $(prePrepend + id).html($(prePrepend + id + " option").sort(
        function (a, b) { return a.text == b.text ? 0 : a.text < b.text ? -1 : 1 })
    );  
}
var selectedType = typeDropdown.selectedItemData();

selectedItemData: function (index) {
    var settings = this.data(extensionName);
    if (typeof (index) === 'undefined') {
        return settings._items ? settings._items[this[0].selectedIndex] || null : null;
    } else {
        this[0].selectedIndex = index;
        this.selectmenu('refresh');
    }
}
这些信息足够吗


提前感谢

这不是问题所在,但是FWIW,我将正则表达式作为正则表达式而不是字符串传递给
match
id.match(/^#/)
。还要注意的是,您依靠
==
将结果匹配转换为字符串(
[“#”]
转换为
“#”
)。它是有效的,但是…就这一点而言,
id.charAt(0)=“#”
会更清晰,可能也会更快…感谢您的输入,但我发现我的问题在这一行中是:设置?设置。_items[this[0].selectedIndex]_items是未排序的,并且此[0]已排序,因此匹配错误。