我正在试图创建64个方块并给每个独特的背景颜色。我非常接近,但我似乎只能得到一种随机颜色。多循环结果for循环?
function randomCol() {
return Math.floor(Math.random()*16777215).toString(16);
}
$(function(){
for(i=0; i<64; i++) {
$('<div class="square"></div>').insertAfter(".starter");
$(".square").css({'background':'#' + randomCol()});
}
});
“一个随机颜色” ,因为对'Math.random()'的调用每次都返回相同的数字? – KRyan 2012-08-01 20:39:58