<html>
<body>
<script type ="text/javascript" >
function AscSort(x, y){
xlen = x.split("|")[1].length;
ylen = y.split("|")[1].length;
return xlen == ylen ? 0 : (xlen > ylen ? 1 : - 1 );
}
function DescSort(x, y){
xlen = x.split("|")[1].length;
ylen = y.split("|")[1].length;
return xlen == ylen ? 0 : (xlen > ylen ? - 1 : 1 );
}
var y = hot_city = ["1|aaa","1|bbbb","15|c","1|dd","1|e"];
y.sort(AscSort);
document.write(y);
</script>
</body>
</html >
以上是对数组的排序。主要是要实现排序的方法:DescSort,AscSort。
可以根据需要自行扩展。