“Uncaught SyntaxError:意外的令牌(”。语法对我来说很好看

时间:2014-11-08 16:21:24

标签: jquery

控制台输出"意外令牌{"在if(message.indexOf.("how are you")>=0){行。

function send_message(message){                     


    var prevState = $("#container").html();             

    if (prevState.length > 3){                      
        prevState = prevState + "<br>";
    }

    $("#container").html(prevState + "<span class='current_msg'> + '<span class = 'bot'>Chatbot: </span>' + message</span>");
    $(".current_msg").hide();                     
    $(".current_msg").delay(slow).fadeIn();                                  
    $(".current_msg").removeClass("current_msg");  
}

 var="username";
    function ai(message){                             
        if (username.length<3){    /*checks to see if var is empty*/                       
            username = message;                           
            send_message("Nice to meet you " + username + ", how are you doing?");
        }
        if(message.indexOf.("how are you")>=0){       /*error here*/    
            send_message("me's good");                    
        }       
        if(message.indexOf.("time")>=0){                  
            var date = new Date();
            var h = date.getHours();
            var m = date.getMinutes();
            send_message("time: " + h + ":" + m);                        
        } 
    }

2 个答案:

答案 0 :(得分:1)

if(message.indexOf.("how are you")>=0){ /*error here*/行上indexOf后有一个额外的点。 if(message.indexOf.("time")>=0){

上的错误相同

答案 1 :(得分:0)

你应该犯这样的错误:

 if(message.indexOf("time") >= 0 ){                  

 }