js随机模块颜色

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=gb2312"/>
<title>js </title>
</head>
<body>
<script type="text/javascript">

function getcl(){
var arr = []                                             
i =0;                                                    
C = '0123456789ABCDEF';                                  
while(i++ < 6){                                       
x=Math.random()*16;                                
b=parseInt(x);                                    
c=C.substr(b,1);                               
arr.push(c);                                    
}
var cl = "#"+ arr.join('');                            
return cl;
}
document.write(cl);                               
function setColor(){                                
document.getElementById("myDiv").style.backgroundColor = getcl();       
}
</script>
<div id="myDiv" style="200px;height:200px;"></div>
<input type="button" value="myDiv"
onclick="setColor()" />
</body>
</html>
..
原文地址:https://www.cnblogs.com/shoolnight/p/6410583.html