【发布时间】:2015-09-09 07:39:04
【问题描述】:
我正在尝试为表单制作一个开/关按钮。按钮的样式取决于复选框的值(选中/未选中)并且复选框本身是隐藏的。我知道您可以使用 css 来管理样式(例如标签按钮的颜色)。有什么办法也可以改变它父母的风格吗?
HAML (RoR):
%label.primary_btn
set as primary
= f.check_box :is_on, style: 'display:none;'
HTML:
<label class="primary_btn">
On/Off Button
<input name="post[images_attributes][0][is_on]" type="hidden" value="0"><input id="post_images_attributes_0_is_on" style="display:none;" type="checkbox" value="1">
</label>
CSS:
.primary_btn {
float: left;
clear: both;
padding: 6px 10px;
border-top-left-radius: 9px;
border-top-right-radius: 9px;
border-bottom-right-radius: 9px;
border-bottom-left-radius: 9px;
color: white;
box-shadow: black 0px 1px 4px -1px;
cursor: pointer;
background-color: #6d6d6d;
}
补充说明:
我不能在标签中使用'for',因为我不能调用嵌套字段:is_on 的id。谢谢!
【问题讨论】:
-
感谢@jcuenod,我不能使用该解决方案的原因是该应用程序是用 RoR 编写的,我无法让 nested_form 库提供“for”设置标签标签。 .
-
我很好奇为什么这对你不起作用:api.rubyonrails.org/classes/ActionView/Helpers/…
-
嗨@jcuenod,感谢您发送该邮件!这是一个嵌套属性,所以我不知道如何为该字段生成
id。 -
可能比找到解决方法更好。
标签: jquery html css ruby-on-rails