如何在ejs中编写或调整条件? [英] how to write or condition in ejs?

查看:111
本文介绍了如何在ejs中编写或调整条件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在ejs模板中编写条件。我厌倦了以下内容

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.

推荐答案

如果使用强等号(===而不是==),请确保变量包含整数。

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

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

或在变量周围使用parseInt

Or use parseInt around your variable

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

这篇关于如何在ejs中编写或调整条件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆