jQuery语法错误?'if'和'else'语句中的Css和Animate

Eva*_*nss 2 jquery

编辑 - 我改变了我的代码:

这很好用:

$(".image-div").click(function () {
        if ($(this).css('z-index') == 1) 
            $(this).css('z-index','2');
        else 
            $(this).css('z-index','1');
});
Run Code Online (Sandbox Code Playgroud)

这也有效:

    $(".image-div").click(function () {
        if ($(this).css('z-index') == 1) 
            $(this).animate({
                width: '500px'
            }, 5000, function() {
                // Animation complete.
            });
        else 
            $(this).animate({
                width: '250px'
            }, 5000, function() {
                // Animation complete.
            });
    });
Run Code Online (Sandbox Code Playgroud)

但这没有做任何事情:

    $(".image-div").click(function () {
        if ($(this).css('z-index') == 1) 
            $(this).css('z-index','2');
            $(this).animate({
                width: '500px'
            }, 5000, function() {
                // Animation complete.
            });
        else 
            $(this).css('z-index','1');
            $(this).animate({
                width: '250px'
            }, 5000, function() {
                // Animation complete.
            });
    });
Run Code Online (Sandbox Code Playgroud)

谢谢

Joh*_*ler 7

是.在if之前和之后没有开始{或结束}.

此外,它看起来像});底部的双.