如何根据EJ中的res.Local变量添加按钮类?
我的页面上有按钮。有些将根据res.locals变量停用。但是,我不知道如何使用EJ添加类。我想做这样的事情:
<button class="class1 class2 <% if (res.locals.myVariable === "a") { %> class3 <% } >" />
<button class="class1 class2 <% if (res.locals.myVariable === "b") { %> class4 <% } >" />
只有设置为“ A”时,只有第一个按钮才有Class3,并且仅如果将myvariable设置为“ b”时,第二个按钮才有class4。
我该怎么做? EJS是要走的路还是有更好的解决方案?
I have buttons on a page. Some will be deactivated based on a res.locals variable. However, I can't figure out how to add a class using ejs. I'm looking to do something like this:
<button class="class1 class2 <% if (res.locals.myVariable === "a") { %> class3 <% } >" />
<button class="class1 class2 <% if (res.locals.myVariable === "b") { %> class4 <% } >" />
The first button would only have class3 if myVariable was set to "a", and the second button would only have class4 if myVariable was set to "b".
How can I do this? Is ejs the way to go or is there a better solution?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以只使用应用程序中定义的变量名称。如果定义
res.locals.myvariable = someValue;
,那么您可以简单地使用这样的myvaria -variable:You can just use your variable name which you defined with res.locals in your app. If you defined
res.locals.myVariable = somevalue;
then you can simply use myVariable like this: