Can't make multiple if conditions in JavaScript?

前端 未结 6 676
一整个雨季
一整个雨季 2021-01-28 23:15

I have absolutely no idea why this is not working. Makes no sense to me.

This returns a \"syntax error: parse error\":

if ($(this).attr(\"id\") === \'se         


        
6条回答
  •  独厮守ぢ
    2021-01-28 23:27

    In JavaScript = is used to assign values, while == and === are used to compare them.

    When you put opening = true in your if statement, you aren't checking if opening is true, you are setting opening to true. Try using == instead.

    For example,

    var x = 5;
    if (x == 10) {
        alert("x is 10");
    } else {
        alert("x isn't 10");
    }
    

    will display "x isn't 10", while

    var x = 5;
    if (x = 10) {
        alert("x is 10");
    } else {
        alert("x isn't 10");
    }
    

    will display "x is 10".

提交回复
热议问题