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 = [44, 12, 32, 23, 56, 78]; 14 //slice方法从索引为0位置开始提取3个元素 15 //返回一个新的数组,包含从 start 到 end (不包括该元素)的 arrayObject 中的元素。 16 partMembers = members.slice(0, 3); 17 $('p.firstHalf').html(partMembers.join("<br />")); 18 $('p.secondHalf').html(members.join("<br />")); 19 20 //合并数组 21 var v1 = ["Johon", "mickey"]; 22 var v2 = ["Wold", "Fond"]; 23 //concat() 方法用于连接两个或多个数组。 24 v1 = v1.concat(v2); 25 $('p.merge').html(v1.join("<br />")); 26 27 //将数值数组转换为字符串并去子字符串 28 var str = members.join(""); 29 var substr = str.substr(0, 5); 30 $('p.substr').html(substr); 31 32 33 }); 34 </script> 35 </head> 36 <body> 37 <h3>Members of my team are as follow: </h3> 38 <p class="firstHalf" /> 39 <p class="secondHalf" /> 40 <p class="merge" /> 41 <p class="substr" /> 42 </body> 43 </html>