<!DOCTYPE html> <html> <head> <title>javascript排序</title> <meta charset="UTF-8"> <script type="text/javascript"> //根据数字进行函数的排序 function sortByNum(a,b){ return a-b; } var as = [1,2,"11","33","12",190]; //对于js而言,默认是按照字符串来实现排序的 as.sort(sortByNum); alert(as); </script> </head> <body> </body> </html>
时间: 2024-11-07 07:03:53