Я попробовал все три из них, но, похоже, текст не изменился. У меня есть набор случайных кавычек, которые я хочу отобразить на экране, и я пытаюсь их изменить, но методы jquery, которые я использовал, похоже, не работают. Вот мой код html и javascript.
вот фрагмент моего текущего кода и того, что я на самом деле пробовал:
var main = function() {
var colors = ["#ED2007", "#EDAB07", "#ECF30A", "#69F30A", "#0AF3E8", "#0A69F3", "#DE0AF3", "#F30ADE"];
var quotes = [
"If you have nothing, are you a nillionaire?",
"Turning up the volume is like zooming in, but with sound.",
"If I eat myself, will I get twice as big, or disappear completely?",
"Out of my mind. Back in five minutes",
"I’m not a complete idiot — Some parts are missing."
];
//begin
//when btn-1 is click, perform following
$(".btn-1").click(function(){
var $this = $(this);
$this.button('loading');
setTimeout(function() {
//begin loop
for(var i = 0; i < quotes.length; i++){
var randQuote =
((Math.random() * quotes[i].length-1) + 0);
switch(randQuote){
case 0:
$('#quote').html("If you have nothing, are you a nillionaire?");
break;
case 1:
$('#quote').html("Turning up the volume is like zooming in, but with sound.");
break;
case 2:
$('#quote').html("If I eat myself, will I get twice as big, or disappear completely?");
break;
case 3:
$('#quote').html("Out of my mind. Back in five minutes");
break;
case 4:
$('#quote').html("I’m not a complete idiot — Some parts are missing.");
break;
default:
$('#quote').html("Press New Quote Button for a random quote");
}
}
//end loop
for(var j = 0; j < colors.length; j++){
var randColor = Math.floor((Math.random() * colors[j].length-1) + 0);
switch(randColor){
case 0: document.body.style.backgroundColor = "#ED2007";
$this.css('background-color', '#ED2007');
break;
case 1:
document.body.style.backgroundColor = "#EDAB07";
$this.css('background-color', '#EDAB07');
break;
case 2:
document.body.style.backgroundColor ="#ECF30A";
$this.css('background-color', '#ECF30A');
break;
case 3:
document.body.style.backgroundColor = "#69F30A";
$this.css('background-color', '#69F30A');
break;
case 4:
document.body.style.backgroundColor ="#0AF3E8";
$this.css('background-color', '#0AF3E8');
break;
case 5:
document.body.style.backgroundColor = "#0A69F3";
$this.css('background-color', '#0A69F3');
break;
case 6:
document.body.style.backgroundColor = "#DE0AF3";
$this.css('background-color', '#DE0AF3');
break;
case 7:
document.body.style.backgroundColor="#F30ADE";
$this.css('background-color', '#F30ADE');
break;
default:
document.body.style.backgroundColor="#00ccff";
$this.css('background-color', '#00ccff');
}
}
$this.button('reset');
}, 4000);
});
//end
//when tumblr btn is click, perform following
$(".fa-tumblr-square").click(function(){
location.href = "https://www.tumblr.com/";
});
//when twitter btn is click, perform following
$(".fa-twitter-square").click(function(){
location.href = 'https://twitter.com/intent/tweet?text=';
});
};
$(document).ready(main);
Я попробовал все три из них, но, похоже, текст не изменился. У меня есть набор случайных кавычек, которые я хочу отобразить на экране, и я пытаюсь их изменить, но методы jquery, которые я использовал, похоже, не работают. Вот мой код html и javascript. вот фрагмент моего текущего кода и того, что я на самом деле пробовал:
var quotes = [ "If you have nothing, are you a nillionaire?", "Turning up the volume is like zooming in, but with sound.", "If I eat myself, will I get twice as big, or disappear completely?", "Out of my mind. Back in five minutes", "I’m not a complete idiot — Some parts are missing." ];
//begin //when btn-1 is click, perform following $(".btn-1").click(function(){ var $this = $(this); $this.button('loading'); setTimeout(function() { //begin loop
for(var i = 0; i < quotes.length; i++){ var randQuote = ((Math.random() * quotes[i].length-1) + 0);
switch(randQuote){ case 0:
$('#quote').html("If you have nothing, are you a nillionaire?");
break;
case 1:
$('#quote').html("Turning up the volume is like zooming in, but with sound.");
break;
case 2:
$('#quote').html("If I eat myself, will I get twice as big, or disappear completely?");
break;
case 3:
$('#quote').html("Out of my mind. Back in five minutes");
break;
case 4:
$('#quote').html("I’m not a complete idiot — Some parts are missing.");
break;
default:
$('#quote').html("Press New Quote Button for a random quote");