未捕获的SyntaxError:意外的令牌{

时间:2012-09-12 20:17:28

标签: javascript jquery

当前使用的jQuery

$("#like_button").live("click", function(){
    var status = $(this).data("status");
    var id = $(this).data("id");
    var count = $(this).html();

        if(status === 1){
            like(id);
            $(this).removeClass("likes");
            $(this).addClass("liked");
            count++;
            $(this).html(count);
        }elseif(status === 2){
            like(id);
            $(this).removeClass("liked");
            $(this).addClass("likes");
            count--;
            $(this).html(count);
        }   else   {
            // do nothing
        }

        return false;

});

错误

Uncaught SyntaxError: Unexpected token { (Line 529)

以下是这一行,

}elseif(status === 2){

如果您需要更多信息来帮助我,请务必询问。

3 个答案:

答案 0 :(得分:12)

JavaScript使用else if,而非elseif

答案 1 :(得分:1)

阅读本教程以了解有关if else语句http://www.w3schools.com/js/js_if_else.asp

的更多信息

答案 2 :(得分:1)

本声明

}elseif(status === 2){

必须是

 }else if(status === 2){

其他之间缺少空格

相关问题