2011-07-23 62 views

回答

4
var random_elem = $('.yourclass').eq(Math.floor(Math.random()*$('.yourclass').length)); 
1

試試這個:

jQuery.jQueryRandom = 0; 
jQuery.extend(jQuery.expr[":"], 
{ 
    random: function(a, i, m, r) { 
     if (i == 0) { 
      jQuery.jQueryRandom = Math.floor(Math.random() * r.length); 
     }; 
     return i == jQuery.jQueryRandom; 
    } 
}); 

var randomElem = $(".className:random"); 

原稿的文章:http://blog.mastykarz.nl/jquery-random-filter/

相關問題