我想弄清楚是否有可能首先選擇一個隨機數組(加載),然後從這個選定的數組中的元素。因此,例如,我有:選擇隨機數組,然後從這個數組中的元素
var colorsOne = ["#CCCCCC","#333333","#990099","#990099"];
var colorsTwo = ["#CCCCCC","#333333","#990099","#990099"];
var colorsThree = ["#CCCCCC","#333333","#990099","#990099"];
var colorsFour = ["#CCCCCC","#333333","#990099","#990099"];
var colorsFive = ["#CCCCCC","#333333","#990099","#990099"];
var colorsSix = ["#CCCCCC","#333333","#990099","#990099"];
var colorsSeven = ["#CCCCCC","#333333","#990099","#990099"];
var colorsEight = ["#CCCCCC","#333333","#990099","#990099"];
var colorsNine = ["#CCCCCC","#333333","#990099","#990099"];
var colorsTen = ["#CCCCCC","#333333","#990099","#990099"];
var colorsEleven = ["#CCCCCC","#333333","#990099","#990099"];
var colorsTwelve = ["#CCCCCC","#333333","#990099","#990099"];
12陣列(每一個最終將被用不同的十六進制代碼填充),我首先需要選擇從這個數組這些陣列中的一個,然後一個十六進制碼(隨機)。
例如
var rand = Math.floor(Math.random() * 4);
$('.header-wrap').css("background-color", colorsEight[rand]);
這將需要一個隨機元素從coloursEight
數組,但我不得不編程,我需要隨機先選擇一個陣列,然後從這個數組中的元素。
任何建議,將不勝感激!
你可以把它們組織成二維數組結構嗎? –
使用對象或數組來存儲十二個數組,而不是單獨的標識符。 – guest271314