【发布时间】:2016-03-07 04:35:35
【问题描述】:
我想每 6 秒获取一组引号并在我的页面上显示一个不同的引号。
我尝试过使用循环遍历数组并淡入新 qoute 的 javascript 函数。但我不断收到错误qoutes 未定义。我尝试将数组移入函数和$(document).ready() 函数,但仍然出现相同的错误。
下面是我的 app.js 代码:
var quotes = [
"Don't Limit Your Challenges, Challenge Your Limits.",
"If the doors of perception were cleansed every thing would appear to man as it is, Infinite.",
"The Power of Imaginiation Makes Us Infinite",
"The finite mind tries to limit the infinite.",
"The Only Limits In Our Life Are Those We Impose on Ourselves."
];
var quoteTimer = function(){
for(var i = 0; i< qoutes.length; i++){
$('.container').find('h1').fadeIn().text(qoutes[i]);
}
}
$(document).ready(function(){
setInterval(quoteTimer, 6000);
});
【问题讨论】:
-
请注意,您声明了数组
quotes,但随后您尝试循环一个名为qoutes的数组(它们不一样) - 首先修复错字,如果没有帮助,请重试- 话虽如此,每次调用函数时,您都会在循环内打印所有引号。 -
检查引号的拼写。在 for 循环中。
标签: javascript jquery arrays loops setinterval