2009-08-03 110 views

回答

5

如何:

//generate random number with maximum size of the number of p elements 
var elems = $('p'); 
var rand = Math.floor(Math.random() * elems.length); 
alert(elems.eq(rand).text()); 
+1

注意這會給你一個DOM節點,而不是一個jQuery對象。對於jq對象,使用$('p')。eq(rand); – redsquare 2009-08-03 12:49:46