其他分享
首页 > 其他分享> > css随机改变页面的背景色

css随机改变页面的背景色

作者:互联网

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body id="body">
<input type='button'  value='刷新页面,随机改变颜色'/>
</body>
</html>
<script>
    var r = Math.floor(Math.random() *256);
    var g = Math.floor(Math.random() *256);
    var b = Math.floor(Math.random() *256);
    console.log(b);
    var color = "rgb("+r+","+g+","+b+")";
    console.log(color)
    var bd = document.getElementById("body")
    bd.style.background= color;
</script>

点击刷新按钮,切换颜色

 

标签:floor,color,random,背景色,css,var,256,Math,页面
来源: https://blog.csdn.net/weixin_43230812/article/details/122520926