javascript - 在 html 中的 onclick 方法上将 Rails 对象值设置为 true
问题描述
我在 html(materialize) 中创建了一个复选框,现在单击该复选框后,我想将 Ruby 对象设置为 true。
有没有办法做到这一点。我们也可以使用 Js 吗?我现在什至会准备一个 hacky 解决方案。
#_form.html.erb
<%= form_with(model: export_application, local: true, html: {multipart: true}, id: "export-application-portal") do |form| %>
<div class="input-field col s12 m12">
<label>Haben Sie schon einmal Hermesdeckungen genutzt?</label>
<p>
<label for="Hermes-y">
<input type="checkbox" class="yes yes-no-btns" id="export_application_has_previously_used_hermes_cover" name="export_application[has_previously_used_hermes_cover]" value="true"/>
<span class="yes yes-no-btns" onclick="previouslyHermesInsuranceUsed()" > Yes</span>
</label>
</p>
</div>
<div class="input-field col s12 m12">
<input class="handex-btn" type="submit" name="submit" value="Antrag Shicken">
</div>
<% end %>
function previouslyHermesInsuranceUsed() {
var x = document.getElementById("newAtHermesDeckung");
if (x.style.display === "block") {
x.style.display = "none";
}
}
我已经尝试了几个小时,但无济于事。
解决方案
推荐阅读
- c++ - 对“__imp_PlaySoundA”的 Clion 未定义引用无法链接到 winmm.ilb
- arrays - 在随机选择数组中的元素的代码之上对数组的元素进行改组会增加随机性吗?
- pandas - 使用 matplotlib 条向多条图添加值
- applescript - 使用 AppleScript 从 .txt 文件中读取时间/日期变量
- makefile - 用于检查拼写的 Makefile
- react-native - 警告:forwardRef 渲染函数只接受两个参数:props 和 ref。您是否忘记使用 ref 参数?本机基础
- c# - System.ArgumentException: 'myObject' 类型的对象无法转换为'System.Collections.Generic.List`1[myObject]' 类型。
- bash - Bash jq 包含搜索键
- node.js - 我有多个相互引用的猫鼬模式。我正在使用 gql-compose-mongoose。如何将一个文档的 objectID 推送到另一个文档中?
- c# - 在其视图模型(Prism WPF)中动态加载用户控件和设置属性