复制代码代码如下:
<!Doctype HTML公共“ - // W3C // DTD XHTML 1.0 Transitional // en”“” http://www.org/tr/tr/xhtml1/dtd/xhtml1-xhtml1-transitional.transitional.dtdd'>
<html xmlns =“ http://www.w3.org/1999/xhtml”>
<头>
<meta http-equiv =“ content-type” content =“ text /html; charset = utf-8” />
<style type =“ text/css”>
身体{
字体大小:12px;
字体家庭:“ Courier New”,Courier,Monopsace;
信件间隔:5px;
}
ul {
列表风格:无;
}
li {
宽度:130px;
身高:130px;
线高:130px;
垂直分组:中间;
文字平衡:中心;
浮子:左;
左键:20px;
}
</style>
<script src =“ http://code.jquery.com/jquery-1.11.0.min.js”> </script>
<Title> JavaScript生成随机颜色</title>
<脚本类型=“ text/javascript”>
$(function(){
$(“ ul li”)。每个(function(){
$(this).css(“背景色”,getRandomColor());
});
}))
函数getRandomColor()
{
var c ='#';
var carray = ['0','1','2','3','4','4','5','6','7','8','8','9','a','','b',b','c','c',d d',d',e','f'];
for(var i = 0; i <6; i ++)
{
var cindex = Math.Round(Math.random()*15);
C += Carray [Cindex];
}
返回c;
}
</script>
</head>
<身体>
<div>
<ul>
<li>第一个色块</li>
<li>第二个色块</li>
<li>第三个色块</li>
<li>第四个色块</li>
</ul>
</div>
</body>
</html>