サマリー:<!DOCTYPE html><html> <head> <meta charset="UTF-8"> <title> divbackground </title> <style> div{width:100px;
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title> divbackground </title>
<style>
div{width:100px;height:200px;margin:0px auto;border:1px solid red;}
</style>
</head>
<body>
<div id="d1"></div>
</body>
<script>
var d1= document.getElementById("d1");
function foo(){
var arr=[0,1,2,3,4,5,6,7,8,9,"a","b","c","d","e","f"]
var color = "#"+arr[Math.floor(Math.random()*arr.length)]+arr[Math.floor(Math.random()*arr.length)]+arr[Math.floor(Math.random()*arr.length)]+arr[Math.floor(Math.random()*arr.length)]+arr[Math.floor(Math.random()*arr.length)]+arr[Math.floor(Math.random()*arr.length)];
d1.style.background = color;
}
var t = setInterval(foo,500);
</script>
//用到了隨機(jī)數(shù)字
</html>
添削の先生:天蓬老師添削時(shí)間:2019-03-28 10:22:27
先生のまとめ:只要能打亂RGB中的數(shù)值, 就可以實(shí)現(xiàn)隨機(jī)變化 , 要注意變化 的范圍就可以了