-2

我无法理解我的 jQuery 代码中有什么不正确的地方:

function BTTS(){

    $('#banner-title span').fadeOut('fast',function() {
        $('#banner-title span').replaceWith('Rental Program');
    };
}

$(document).ready(function(){
    // RUN BTTS FUNCTION
    setInterval('BTTS()', 7500);
}
4

1 回答 1

2

代码中有语法错误

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

更新的解决方案

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

演示:小提琴

于 2013-05-27T03:42:50.817 回答