This code is working fine if ($(this).val() == “Spine”) but not ($(this).val() == “Spine”||“Brian”)

后端 未结 6 996
北海茫月
北海茫月 2021-01-20 04:28

This code is working fine if ($(this).val() == \"Spine\") but if ($(this).val() == \"Spine\"||\"Brian\") then the selection menu closes then opens

6条回答
  •  没有蜡笔的小新
    2021-01-20 04:51

    What you're looking for is:

    if ($(this).val() == "Spine"|| $(this).val() == "Brain")
    

    As is, you code has an error regarding Operator Precedence. I'd recommend looking at https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Operators/Operator_Precedence

    Your version will always return true, as any non-zero length string will resolve to true when used in a boolean context. There are many articles on Javascript's quirky behaviour when it comes to boolean evaluations. A basic outline of some of some of the most common ones can be found at http://javascriptweblog.wordpress.com/2011/02/07/truth-equality-and-javascript/

提交回复
热议问题