【发布时间】:2019-07-18 06:51:57
【问题描述】:
我有一个 rails 表单。当一个复选框被选中时(在数据库中为真),我想保持 div 隐藏。我找到了其他解决方案,但在页面重新加载时它会重新出现,如果选中或为真,我想保持 div 隐藏。
<div class="form-group">
<%= form.check_box :tos_checkbox, class: "terms_of_services" %>
<%= form.label :tos_checkbox, "Agree to TOS" %>
</div>
<div id="hide_if_above_checked">
Do You Agree to Our TOS
</div>
我知道这个脚本行不通,但一直在尝试几个不同的例子来解决我的问题。
$(function () {
$('.terms_of_services').change(function () {
if(checkbox.checked == true){
document.getElementById("hide_if_above_checked").setAttribute("d-none");
}else{
document.getElementById("hide_if_above_checked").removeAttribute("d-none");
}
});
});
【问题讨论】:
标签: javascript jquery ruby-on-rails checkbox