小编Wax*_*axi的帖子

不明白为什么我的setInterval + jQuery不起作用

总而言之,我正在尝试使用随机报价生成器.我的代码非常简单......

var myQuotes = [

    {
    quote: "To err is human; to forgive, divine.",
    cite: "Alexander Pope"},

    {
    quote: "Reports of my death have been greatly exaggerated.",
    cite: "Mark Twain"} 

];

var randomQuote = Math.floor(Math.random() * myQuotes.length);

$('.quote').html(myQuotes[randomQuote].quote); // #1
$('.cite').html(myQuotes[randomQuote].cite); 

setInterval(function() {

    $('.quote').fadeOut();

    $('.quote').fadeIn().html(myQuotes[randomQuote].quote); // #2

}, 3000);
Run Code Online (Sandbox Code Playgroud)

在加载时,它显示#1就好了,但#2似乎不起作用......它只是保持闪烁与之前相同的一个,#1中的那个.我对此不了解什么?

javascript jquery setinterval

0
推荐指数
1
解决办法
203
查看次数

标签 统计

javascript ×1

jquery ×1

setinterval ×1