复制代码代码如下:
<!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">
<head>
<Meta http-equiv = "content-type" content = "text /html; charset = utf-8" />
<style type = "text/css">
体{
フォントサイズ:12px;
フォントファミリー:「クーリエニュー」、クーリエ、モノスペース。
レター間隔:5px;
}
ul {
リストスタイル:なし;
}
li {
幅:130px;
高さ:130px;
ラインハイト:130px;
垂直アライイン:中央;
テキストアライグ:センター;
フロート:左;
マージン左:20px;
}
</style>
<Script src = "http://code.jquery.com/jquery-111.0.min.js"> </script>
<Title> JavaScript </title>
<script type = "text/javascript">
$(function(){
$( "ul li")。各(function(){
$(this).css( "background-color"、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;
}
</script>
</head>
<body>
<div>
<ul>
<li>第一个色块</li>
<li>第二个色块</li>
<li>第三个色块</li>
<li>第四个色块</li>
</ul>
</div>
</body>
</html>