-1

我觉得我应该能够从谷歌搜索中找到这个,但没有,所以我会在这里问它。

我在第二个 if 语句上不断收到错误,所以我想知道是否不允许在预先存在的 if/else 语句中放置另一个 if 语句。

感谢您的关注。

function flipImages(){
    currentImage = flipArray[i];

    if (i == 6) {
        clearInterval(interval)
    }
    else {
        // add an opacity animation to the flip so that it is less jarring 
        // set at a 100ms fade in

        $(currentImage).animate({
            opacity: 1 
        }, 100, function() {
            console.log(flipArray[i]);
        }

        // also animate in the child divs of the currentImage (which will only be text on 
        // the "final" div) 
        if ( $(currentImage).children().hasClass('final'){
            $(currentImage).children().animate({
                opacity: 1,
                left: '+=50'
            }, 500, function(){
                console.log( $(currentImage).children() );
            });
        });
    );
    i++;
    };              
}
4

2 回答 2

1

您缺少几个右括号和大括号,或者在错误的位置有一些。使用带有语法突出显示的体面的编辑器可以很容易地发现这样的错误。

作为记录,是的,可以嵌套if语句 - 假设您的语法是正确的。

这是您的代码的更正版本:

function flipImages(){
    currentImage = flipArray[i];

    if (i == 6) {
        clearInterval(interval)
    }
    else {
        // add an opacity animation to the flip so that it is less jarring 
        // set at a 100ms fade in

        $(currentImage).animate({
            opacity: 1 
        }, 100, function() {
            console.log(flipArray[i]);
        });

        // also animate in the child divs of the currentImage (which will only be text on 
        // the "final" div) 
        if ($(currentImage).children().hasClass('final')) {
            $(currentImage).children().animate({
                opacity: 1,
                left: '+=50'
            }, 500, function(){
                console.log( $(currentImage).children() );
            });
        };
        i++;
    };              
}
于 2013-02-12T16:35:37.983 回答
0

你错过了 ) 之后if ($(currentImage).children().hasClass('final')还有几个分号,这使它成为无效的 js。

function flipImages() {
    currentImage = flipArray[i];

    if (i == 6) {
        clearInterval(interval);
    } else {
        // add an opacity animation to the flip so that it is less jarring 
        // set at a 100ms fade in

        $(currentImage).animate({
            opacity: 1
        }, 100, function () {
            console.log(flipArray[i]);
        });

        // also animate in the child divs of the currentImage (which will only be text on 
        // the "final" div) 
        if ($(currentImage).children().hasClass('final')) {
            $(currentImage).children().animate({
                opacity: 1,
                left: '+=50'
            }, 500, function () {
                console.log($(currentImage).children());
            });
        }
        i++;
    }
}

在这里检查

于 2013-02-12T16:48:57.113 回答