.html() ,innerHTML() и .text() не меняют текстHtml

Программисты Html
Ответить
Anonymous
 .html() ,innerHTML() и .text() не меняют текст

Сообщение Anonymous »

Я попробовал все три из них, но, похоже, текст не изменился. У меня есть набор случайных кавычек, которые я хочу отобразить на экране, и я пытаюсь их изменить, но методы 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);

Код: Выделить всё







Random Quote Machine






"Press New Quote Button for a random quote"


[i][/i]
[i][/i]

New Quote



[url=https://codepen.io/natekicksa/]By:Nate[/url]





Подробнее здесь: https://stackoverflow.com/questions/485 ... g-the-text
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Html»