0

我对如何在 jquery 的下拉列表中应用排序有点困惑

例如苹果、猫、卡车、苹果、猫、卡车

它应该像在下拉列表中......苹果苹果猫猫卡车卡车

如何在 jquery 中实现这一点,以便它也可以看到大写和小写。

4

1 回答 1

0

在自定义排序方法中降低数组项的大小写,如下jsfiddle

var arr= [  "apple","cat","truck","APPLE","CAT","TRUCK"];

arr.sort(sort);
function sort(a, b){

   if(a.toLowerCase() > b.toLowerCase()) return 1;
       if(a.toLowerCase() < b.toLowerCase()) return -1;
    return 0;
}
于 2012-10-06T16:47:07.027 回答