-1

グーグル検索で探せるはずなのに見つからなかったのでこちらで質問させていただきます。

2 番目の 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')U は、無効な 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 に答える