复制代码代码如下 :
<! doctype html public "-// w3c // dtd xhtml 1.0 Transitional // en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">
<html xmlns = "http://www.w3.org/1999/xhtml">
<헤드>
<meta http-equiv = "content-type"content = "text /html; charset = utf-8" />
<스타일 유형 = "텍스트/CSS">
몸{
글꼴 크기 : 12px;
Font-Family : "Courier New", Courier, Monospace;
글자 스페이스 : 5px;
}
ul {
목록 스타일 : 없음;
}
Li {
너비 : 130px;
높이 : 130px;
라인 높이 : 130px;
수직 정상 : 중간;
텍스트 정렬 : 센터;
플로트 : 왼쪽;
마진 왼쪽 : 20px;
}
</스타일>
<script src = "http://code.jquery.com/jquery-1.11.0.min.js"> </script>
<title> javaScript 生成随机颜色 </title>
<script type = "text/javaScript">
$ (function () {
$ ( "ul li"). 각 (function () {
$ (this) .css ( "배경색", getrandomcolor ());
});
})
함수 getRandomColor ()
{
var c = '#';
var carray = [ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'];
for (var i = 0; i <6; i ++)
{
var cindex = math.round (math.random ()*15);
C += Carray [Cindex];
}
반환 c;
}
</스크립트>
</head>
<body>
<div>
<ul>
<li> </li>
<li> </li>
<li> </li>
<li> </li>
</ul>
</div>
</body>
</html>