<div class="codetitle"> <span><a style="CURSOR: pointer" data="13393" class="copybut" id="copybut13393" onclick="doCopy('code13393')"><u>复制代</u></a></span> 代码如下:</div> <div class="codebody" id="code13393"> <br><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <BR><html xmlns="http://www.w3.org/1999/xhtml"> <br> <br><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <br><style type="text/css"> <br>body{ <br>font-size:12px; <br>font-family:"Courier New"、Courier、等幅; <br>文字間隔:5px; <br>} <br>ul{ <br>リストスタイル:なし; <br>} <br>li{ <br>幅:130px; <br>高さ:130ピクセル; <br>行の高さ:130px; <br>vertical-align:middle; <br>text-align:center; <br>浮動小数点:左; <br>マージン左:20px; <br>} <br></style> <br><script src="http://code.jquery.com/jquery-1.11.0.min.js"></script> <br><title>javascript生成随机颜色</title> <br><script type="text/javascript"> <br>$(function(){ <br>$("ul li").each(function(){ <br>$(this).css("background-color",getRandomColor()); <br> }); <br>}) <br>関数 getRandomColor() <br>{ <br>var c = '#'; <br>var cArray = ['0','1','2','3','4','5','6','7','8','9','A' ,'B','C','D','E','F']; <br>for(var i = 0; i { <br>var cIndex = Math.round(Math.random()*15); <br>c = cArray[cIndex]; <br>} <br>c を返します。 <br>} <br><br></script> <br></head> <br><br> <br><div> <br><ul> <br><li>第一色块</li> <br><li>第二色块</li> <br><li>第三个色块</li> <br><li>第四个色块</li> <br> </ul> <br> </div> <br></body> <br></html> <br> </div>