简体   繁体   English

如何检查变量是否小于ejs中的某个数字

[英]How can I check if a variable is less then a certain number in ejs

I have the following code我有以下代码

<%if (locals.average > 4.5 && locals.average < 5){%>
              <div>test</div>
<%}%>

If i apply the following code the test div doesnot appear I think the problem is with less than 5 because if I use this only如果我应用以下代码,则不会出现测试 div 我认为问题在于小于 5,因为如果我只使用它

<%if (locals.average > 4.5){%>
              <div>test</div>
<%}%>

It works fine.它工作正常。 How can I use less than symbol in ejs如何在 ejs 中使用小于符号

I'm not familiar with ejs - but assuming your parser is tripping-up on < (eg thinking it's the start of a tag) then use the logical inverse of less-than (which is not-greater-than-or-equal-to ):我对 ejs 不熟悉 - 但假设您的解析器在<上出错(例如认为它是标签的开头)然后使用less-than的逻辑逆( not-greater-than-or-equal-to ):

<% if( locals.average > 4.5 && !( locals.average >= 5 ) ) { %>
              <div>test</div>
<% } %>

That said, the documentation for ejs suggests that your original code should work - as it's just a normal JavaScript expression.也就是说,ejs 的文档表明您的原始代码应该可以工作 - 因为它只是一个普通的 JavaScript 表达式。 If you find out why it really didn't work you should post that as the answer and accept that answer instead of mine.如果您发现它为什么真的不起作用,您应该将其发布为答案并接受该答案而不是我的答案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM