更改div的背景颜色重新加载 [英] Change background color of div on reload

查看:283
本文介绍了更改div的背景颜色重新加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望在每次重新加载窗口时更改为div类的背景颜色。

我使用此代码更改了刷新时正文的背景颜色:

I'm looking to change to background color of a div class every time the window reloads.
I've used this code to change the background color of the body on refresh:

<script type="text/javascript">
<!-- //Enter list of bgcolors:
var bgcolorlist=new Array("silver", "#BAF3C3", "#c3baf3")

document.body.style.background=bgcolorlist[Math.floor(Math.random()*bgcolorlist.length)]
// -->
</script>

但我想要改变'.three'的背景颜色,所以每个div 三将在每次窗口重新加载时选择不同的背景颜色(从一个颜色数组中选择)。

看起来不能弄清楚该怎么做,是不是可能?

But I'm looking to change the background color of '.three' so every div with the class 'three' will have a different background color every time the window reloads (choosing from an array of colors).
Can't seem to figure out how to do this, is it at all possible?

推荐答案

使用此

var bgcolorlist=new Array("silver", "#BAF3C3", "#c3baf3")

$(".three").css("background-color",bgcolorlist[Math.floor(Math.random()*bgcolorlist.length)]);

这篇关于更改div的背景颜色重新加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆