1.
1 <%@ page language="java" contentType="text/html; charset=UTF-8" 2 pageEncoding="UTF-8"%> 3 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 4 <html> 5 <head> 6 <meta http-equiv="Content-Type" content="text/html;charset=utf-8"> 7 <title>字符串数组和数值数组元素排序</title> 8 <link rel="stylesheet" href="./common.css" type="text/css" /> 9 <script src="./jquery-1.5.2.js" type="text/javascript"></script> 10 <script type="text/javascript"> 11 $(document).ready( function() { 12 //字符串数组排序 13 var members = ["John", "Steve", "Marray", "Bon", "Iran"]; 14 members = members.sort(); 15 $('p.sortedStr').html(members.join("<br />")); 16 17 var members = ["John","Steve","Marray","Bon","Iran"]; 18 members = members.sort(); 19 $(".sortedStr1").html(members.join("<br/>")); 20 21 //数值数组排序 22 members = [45, 23, 12, 34]; 23 /* members = members.sort(function(a, b){ 24 return a-b; 25 //上述如果为b-a则降序排列 26 }); */ 27 28 29 memebers = members.sort(function(a,b){ 30 return b-a; 31 }); 32 $('p.sortedNum').html(members.join("<br />")); 33 }); 34 </script> 35 </head> 36 <body> 37 <h3>Members of my team are as follow: </h3> 38 <p class="sortedStr" /> 39 <p class="sortedStr1" /> 40 <p class="sortedNum" /> 41 </body> 42 </html>