此代码通过三个数组洗牌随机顺序每当DIV点击。我想不得不让两个数组“引号”和“作者”显示相同的随机数组顺序。如果x是随机的,我希望“Third”等于“-Third”和“First”等于“-First”或者引号[x] ==作者[x]。随机选择项目从两个数组和匹配的项目责令
也有一个简单的方法来对。就绪和功能。点击结合,所以我不已经把完全相同的代码在这两个?
var colors = ["#3b609b", "#9b3b3b", "#3b9b81", "#7da5a4"];
var quotes = ["First", "Second", "Third", "Fourth"];
var authors = ["-First", "-Second", "-Third", "-Fourth"];
$(document).ready(function() {
//Variables to shuffle through "colors", "quotes" and "authors" arrays.
var rand = Math.floor(Math.random() * colors.length);
var rand2 = Math.floor(Math.random() * quotes.length);
var rand3 = Math.floor(Math.random() * authors.length);
//Display quotes/authors and change background colors.
$("body, .button, .social").css("background-color", colors[rand]);
$(".quote").html(quotes[rand2]).css("color", colors[rand]);
$(".author").html(authors[rand3]).css("color", colors[rand]);
$(".button").click(function() {
//Variables to shuffle through "colors", "quotes" and "authors" arrays.
var rand = Math.floor(Math.random() * colors.length);
var rand2 = Math.floor(Math.random() * quotes.length);
var rand3 = Math.floor(Math.random() * authors.length);
//Display quotes/authors and change background colors when div is clicked.
$("body, .button, .social").css("background-color", colors[rand]);
$(".quote").html(quotes[rand2]).css("color", colors[rand]);
$(".author").html(authors[rand3]).css("color", colors[rand]);
});
});
非常感谢!它现在很好用! – Zach