开发者

I'd like to add a random class to the body element with jQuery

I'd like to be able to have a list of classes (ie. .bgimg1{},.bgimg2{}, .bgimg3{}, etc) and randomly insert one into the body element of my pages.

I can do HTML and CSS, but I'm 开发者_如何学JAVAa programming luddite, so please type slowly. :)


you can do this:

var classes = ['bgimg1','bgimg2', 'bgimg3']; //add as many classes as u want
var randomnumber = Math.floor(Math.random()*classes.length);

$('body').addClass(classes[randomnumber]);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜