2013-06-27 91 views
1

我只是在邏輯運算符中使用If語句。我不知道它爲什麼顯示出sytax錯誤。語法錯誤 - 邏輯語句

var divWidth = $("#columnwraper").width(); //getting the width of the div 
$("#right-button").click(function() { 
    if (cursor != totalWidth && totalWidth !< divWidth) { 
     $box2.animate({ 
      marginLeft : "-=300" 
     }, "fast"); 

     cursor += 100; 
    } 
    // console.log(colwidth.width()); 
}); 

它`表明

[15:18:24.050] SyntaxError: missing) after condition.

我在做什麼錯在這裏?

+2

什麼是'!<'運算符?爲什麼不用'> ='來代替? –

+0

什麼是$ box2 ..? – iJade

+3

注意'!='是*一個*運算符。它不是'!'和'=='的組合。您不能簡單地將'!'與其他操作符(即'!<'無效)結合使用。 –

回答

8

這樣說吧:

if (cursor != totalWidth && !(totalWidth < divWidth)) 

!<不是operator

2

錯誤totalWidth !< divWidth

應該totalWidth < divWidthtotalWidth >= divWidth

+1

或'> ='。我認爲'!'不只是一個錯字。 –

1

始終把邏輯運算符在內部支架像操作:(totalWidth < divWidth)

而且!<不是運營商。 你應該用這個:

if ((cursor != totalWidth) && !(totalWidth < divWidth)) {... }