复制代码代码如下:
<! Doctype html public "-// w3c // dtd xhtml 1.0 transitional // pt" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-bransitional.dtd">
<html xmlns = "http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv = "content-type" content = "text /html; charset = utf-8" />
<style type = "text/css">
corpo{
tamanho de fonte: 12px;
Fonte-família: "Courier New", Courier, Monospace;
Espacamento de cartas: 5px;
}
ul {
estilo de lista: nenhum;
}
li {
Largura: 130px;
Altura: 130px;
altura da linha: 130px;
Alinhamento vertical: meio;
Alinhamento de texto: centro;
flutuar: esquerda;
margem-esquerda: 20px;
}
</style>
<script src = "http://code.jquery.com/jquery-1.11.0.min.js"> </script>
<title> javascript 生成随机颜色 </ititle>
<script type = "text/javascript">
$ (function () {
$ ("ul li"). Cada (function () {
$ (this) .css ("cor de fundo", getrandomcolor ());
});
})
função 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];
}
retornar c;
}
</script>
</head>
<Body>
<div>
<ul>
<li> 第一个色块 </li>
<li> 第二个色块 </li>
<li> 第三个色块 </li>
<li> 第四个色块 </li>
</ul>
</div>
</body>
</html>