html随机获取颜色代码,javascript生成随机颜色示例代码
body{font-size:12px;font-family:"Courier New", Courier, monospace;letter-spacing:5px;}ul{list-style:none;}li{width:130px;height:130px;line-height:130px;vertical-align:middle;text-align:center;float:le
body{
font-size:12px;
font-family:"Courier New", Courier, monospace;
letter-spacing:5px;
}
ul{
list-style:none;
}
li{
width:130px;
height:130px;
line-height:130px;
vertical-align:middle;
text-align:center;
float:left;
margin-left:20px;
}
javascript生成随机颜色$(function(){
$("ul li").each(function(){
$(this).css("background-color",getRandomColor());
});
})
function 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];
}
return c;
}
- 第一个色块
- 第二个色块
- 第三个色块
- 第四个色块
更多推荐

所有评论(0)