原问题帖在这里:http://topic.csdn.net/u/20081130/09/18d455a6-65e1-4d00-aa8c-d9742654cd8c.html 排序前:"Zo","Ad","bC","dad", "bood","bada","Admin","Good","aete","cc","Ko","Beta","Could","AAA" var t = ["Zo","Ad","bC","dad", "bood","bada","Admin","Good","aete","cc","Ko","Beta","Could","AAA"]; //var t = ['aaa','aaaa']; function sort(arr){ for(var i=0; i<arr.length; i++){ for(var j=0; j<arr.length-i-1; j++){ if(compare(arr[j], arr[j+1])>0){ var tmp = arr[j]; arr[j] = arr[j+1]; arr[j+1] = tmp; } } } } function compare(str1, str2){ /** if(str1>str2){ return 1; } return 0; **/ var r = 0; for(var i=0, j=0; i<str1.length&&j<str2.length; i++, j++){ status = 'i=' + i + ' j=' + j; var c1 = str1.charCodeAt(i); var c2 = str2.charCodeAt(j); if(c1>=97) c1-=32; if(c2>=97) c2-=32; if(c1>c2){ return 1; } else if(c1<c2){ return 0; } else if(c1==c2){ if(str1.charCodeAt(i)>str2.charCodeAt(j)){ return 1; } else if(str1.charCodeAt(i)<str2.charCodeAt(j)){ return 0; } else if(str1.charCodeAt(i)==str2.charCodeAt(j)){ continue; } } } if(i!=str1.length){ return 1; } else if(j!=str2.length){ return 0; } } sort(t); alert("排序后:" + t); [Ctrl+A 全选 注:如需引入外部Js需刷新才能执行]