Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我是 Rails 的新手。我在haml中有一个隐藏字段和一个切换按钮。我如何获取隐藏字段的值,如果为 0,那么我将按钮的类更改为活动。我使用 coffescript 为隐藏字段设置一个值。
谢谢
如果您在 DOM 中使用 CoffeeScript 设置隐藏字段,那么您也可以通过 CoffeeScript 很好地添加类:
if $("#my_hidden_element").val() == 0 $("#target").addClass 'active'
解释 HAML 中隐藏字段的值可能需要您嵌入脚本(通常没人想要):)
祝你好运