<!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>
//用到了随机数字
</html>