如何根据EJ中的res.Local变量添加按钮类?

发布于 2025-02-08 01:00:35 字数 411 浏览 0 评论 0原文

我的页面上有按钮。有些将根据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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

凉风有信 2025-02-15 01:00:35

您可以只使用应用程序中定义的变量名称。如果定义res.locals.myvariable = someValue;,那么您可以简单地使用这样的myvaria -variable:

<button class="class1 class2 <% myVariable === 'a' ? 'class3' : 'class4' %>" />

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:

<button class="class1 class2 <% myVariable === 'a' ? 'class3' : 'class4' %>" />
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文