how to write or condition in ejs?

纵然是瞬间 提交于 2019-12-11 16:49:31

问题


How can i write or condition in ejs template.I tired the following

     <%if (user ===0 || user ===1) { %>
      <div id="main_div">
          My content over here
      </div>
        <% } %>

it will satisfy the first condition but not the second one.


回答1:


if you use the strong equality (=== instead of ==) ensure that your variable contains integer.

"1" == 1 // true
"1" === 1 // false

Or use parseInt around your variable

<%if (parseInt(user) ===0 || parseInt(user) ===1) { %>


来源:https://stackoverflow.com/questions/48168887/how-to-write-or-condition-in-ejs

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!