我期待創建一個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