Javascript jQuery-Function-setInterval
我无法理解jQuery代码中的错误:Javascript jQuery-Function-setInterval,javascript,jquery,Javascript,Jquery,我无法理解jQuery代码中的错误: function BTTS(){ $('#banner-title span').fadeOut('fast',function() { $('#banner-title span').replaceWith('Rental Program'); }; } $(document).ready(function(){ // RUN BTTS FUNCTION setInterval('BTTS()', 750
function BTTS(){
$('#banner-title span').fadeOut('fast',function() {
$('#banner-title span').replaceWith('Rental Program');
};
}
$(document).ready(function(){
// RUN BTTS FUNCTION
setInterval('BTTS()', 7500);
}
代码中存在语法错误
function BTTS(){
$('#banner-title span').fadeOut('fast',function() {
$('#banner-title span').replaceWith('Rental Program');
}); //<-- missing ')' here
}
$(document).ready(function(){
// RUN BTTS FUNCTION
setInterval('BTTS()', 7500);
}); //<-- missing ')' here
函数BTTS(){
$(“#标题span”).fadeOut('fast',function(){
$(#标题span')。替换为(“租赁计划”);
});//尝试setInterval('BTTS',7500)
欢迎使用堆栈溢出用户2423612!当您说此功能“不起作用”时,你的确切意思是什么?这有很多不同的含义。检查你的浏览器控制台,看看是否有错误。我检查了一个错误。我几乎肯定的问题在于符号。我认为它不在正确的位置。像{;这样的符号可以使用$(this)。替换为('rent program'))
在完整函数中。不要将字符串传递给setInterval
。此外,在ready()末尾的最后一个}
@undefined same之后缺少一个右括号
alsoThat工作得很好。谢谢!还有人知道我如何让标题每7.5秒更改一次吗?因此,将原始标题从标题1更改为标题2,然后循环回原始标题,依此类推。不停地循环。@ArunPJohny:您仍然忘了更改'BTTS()“ >代码> BTS。如果OP碰巧将<代码> BTS< /Case>函数移动到回调中,它将引入范围问题。还考虑在<代码>上更改StimeTimeOut.Delphi(7500)。fadeOut(…< /代码>)
var titles = ['My Title 1', 'My Title 2'], titleFlag = 0;
function BTTS(){
$('#banner-title span').fadeOut('fast',function() {
titleFlag = (titleFlag + 1) % titles.length;
$('#banner-title span').html(titles[titleFlag]).show();
}); //<-- missing ')' here
}
$(document).ready(function(){
// RUN BTTS FUNCTION
setInterval(BTTS, 2000);
}); //<-- missing ')' here