如何在视图中创建比决定它的逻辑更高的效果?
我的视图中有一个简单的 if 语句,它返回 x = 0 或 1。基于这个简单的结果,我想更改包含整个部分的 div 的样式。
<div>
conditional that returns x=1 vs x=0 (and a few displayed items)
based on this loop, restyle the div
</div>
假设,如果 x = 1,我想要设置背景颜色:rgb(210,215,220);
我怎样才能做到这一点?我对 Javascript 没有经验,但我确信所需的任何代码都会非常简单。谢谢你!
I have a simple if statement in my view that returns x = 0 or 1. Based on this simple result, I want to change the styling of the div that contains the entire section.
<div>
conditional that returns x=1 vs x=0 (and a few displayed items)
based on this loop, restyle the div
</div>
Let's say, if x = 1, I want to make background-color:rgb(210,215,220);
How can I accomplish this? I am not experienced with Javascript but I'm sure any code required would be very simple. Thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将 ID 添加到您的 DIV,如下所示:
然后执行以下操作:
Add an ID to your DIV like:
Then do this:
包含 jQuery,并将 div 的 id 赋予
div
Include jQuery, and give the div's id to
divid