<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> <br> <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, monospace; <BR>letter-spacing:5px; <BR>} <BR>ul{ <BR>list-style:none; <BR>} <BR>li{ <BR>width:130px; <BR>height:130px; <BR>line-height:130px; <BR>vertical-align:middle; <BR>text-align:center; <BR>float:left; <BR>margin-left: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>function 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 < 6;i++) <BR>{ <BR>var cIndex = Math.round(Math.random()*15); <BR>c += cArray[cIndex]; <BR>} <BR>return c; <BR>} <br><br></script> <br> <br><br> <br><div> <br><ul> <br><li>第一个色块</li> <br><li>第二个色块</li> <br><li>第三个色块</li> <br><li>第四个色块</li> <br> </ul> <br> </div> <br> <br> <br> </div>