复制代码代码如下:
<! DocType html public "-// w3c // dtd xhtml 1.0 Transitional // en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transicional.dtd ">
<html xmlns = "http://www.w3.org/1999/xhtml">
<Evista>
<meta http-equiv = "content-type" content = "text /html; charset = utf-8" />
<style type = "text/css">
cuerpo{
tamaño de fuente: 12px;
Font-Family: "Courier New", Courier, Monospace;
Espaciado de letras: 5px;
}
ul {
Estilo de lista: Ninguno;
}
li {
Ancho: 130px;
Altura: 130px;
Línea-aguja: 130px;
Align vertical: medio;
Text-Align: Center;
flotante: izquierda;
margen-izquierda: 20px;
}
</style>
<script src = "http://code.jquery.com/jquery-1.11.0.min.js"> </script>
<title> JavaScript 生成随机颜色 </title>
<script type = "text/javaScript">
$ (function () {
$ ("ul li"). Cada (function () {
$ (this) .css ("color de fondo", getRandomColor ());
});
})
función getRandomColor ()
{
var c = '#';
var carroy = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'];
para (var i = 0; i <6; i ++)
{
var cindex = Math.round (Math.random ()*15);
c += carnado [cindex];
}
regreso c;
}
</script>
</ablo>
<Body>
<div>
<ul>
<li> 第一个色块 </li>
<li> 第二个色块 </li>
<li> 第三个色块 </li>
<li> 第四个色块 </li>
</ul>
</div>
</body>
</html>