题
我有这个javascript:
$('.foto').filter(function(index) {
return index == Math.floor(Math.random() * 8) + 1;
}).trigger('mouseover');
.
我想在照片上模拟悬停效果,但不知何故,过滤功能不起作用。 我也试过
$('.foto:random').trigger('mouseover');
. 解决方案
Try this:
$.fn.rand = function(){
return this.eq(Math.floor(Math.random()*this.length));
};
$(".foto").rand().trigger("mouseover");
Note: you only have to define $.fn.rand
once, usually right after including jquery.
不隶属于 StackOverflow