我期待创建一个Jquery脚本,它将从10列表中随机选择一种颜色,然后将其作为背景颜色应用于一个div,而颜色h1标签。JQuery随机背景颜色和颜色,在2 div的
到目前为止,我有这使得随机颜色:
$(document).ready(function() { var hue = 'rgb(' + (Math.floor((256-199)*Math.random()) + 200) + ','
+ (Math.floor((256-199)*Math.random()) + 200) + ','
+ (Math.floor((256-199)*Math.random()) + 200) + ')';
$('#controls-wrapper').css("background-color", hue);
$('h1').css("color", hue);});
,但我怎样才能使这个从10种颜色列表中随机选择? 我发现了这个,但不知道如何将它应用于bg color div和h1 tag。
$("#controls-wrapper").each(function(){
var colors = ["#CCCCCC","#333333","#990099"];
var rand = Math.floor(Math.random()*colors.length);
$(this).css("background-color", colors[rand]);});
很多谢谢,那是我得到的同样的答案。非常感谢您的帮助! – Hue 2011-05-05 12:50:03