复制代码代码如下::
<! DocType html public "-// w3c // dtd xhtml 1.0 transitional // en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transsitional.dtd">
<html xmlns = "http://www.w3.org/1999/xhtml">
<kopf>
<meta http-äquiv = "content-type" content = "text /html; charset = utf-8" />
<style type = "text/css">
Körper{
Schriftgröße: 12px;
Schriftfamilie: "Courier New", Kurier, Monospace;
Buchstabenabteilung: 5px;
}
ul {
Listenstil: Keine;
}
li {
Breite: 130px;
Höhe: 130px;
Zeilenhöhe: 130px;
vertikaler Align: Mitte;
Text-Align: Mitte;
float: links;
Rand-Links: 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"). Jede (function () {
$ (this) .css ("Hintergrundfarbe", getRandomcolor ());
});
})
Funktion getrandomcolor ()
{
var c = '#';
var carray = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'];
für (var i = 0; i <6; i ++)
{
var cindex = math.round (math.random ()*15);
c += carray [cindex];
}
Rückkehr C;
}
</script>
</head>
<body>
<div>
<ul>
<li> 第一个色块 </li>
<li> 第二个色块 </li>
<li> 第三个色块 </li>
<li> 第四个色块 </li>
</ul>
</div>
</body>
</html>