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 var members = ["Mickey", "William", "Henry"]; 13 $('h2').text('Members of my group: '); 14 $('p').html(members.join("<br />")); 15 16 var memberlist = $("#list"); 17 $.each(members, function(index, value){ 18 //append() 方法在被选元素的结尾(仍然在内部)插入指定内容。 19 memberlist.append(index + " : " + value ); 20 memberlist.append("<li>"+value+"</li>"); 21 }); 22 23 //下面利用jQuery获取li中内容的数组,并计算数组长度 24 var names = $('li').get(); 25 alert("获得了数组,数组长度为:" + names.length); 26 27 }); 28 </script> 29 </head> 30 <body> 31 <h2>Hello</h2> 32 <p></p> 33 34 <ol id="list"> 35 </ol> 36 </body> 37 </html>