如何使用 Javascript 随机更改背景颜色? [英] How can I change the background color randomly with the Javascript?

查看:22
本文介绍了如何使用 Javascript 随机更改背景颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在用户刷新页面后更改背景颜色

I want to change the background colour once the user refresh the page

推荐答案

你可以通过 jQuery 来实现,请查看下面的代码:

You can do it by jQuery, Please check the code below :

$(document).ready(function() {
var randomColor = Math.floor(Math.random()*16777215).toString(16);
    $("#background").css("background-color", '#' + randomColor);
});

这篇关于如何使用 Javascript 随机更改背景颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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