我正在构建一个 Rails 应用程序。我想访问 Java 脚本中的 radio_button 值(在 document.getElementById 中)。以下是 form.html.erb 中的代码片段。 请让我知道如何访问它。我尝试了很多选择。但没有任何效果。
<div class="field">
<div class="container-fluid">
<div class="row">
<div class="col-md-6">
<div class="col-md-4">
<%= "Yet to start" %>
<%= radio_button("section", "1", "Tag1", :checked => true) %>
</div>
<div class="col-md-4">
<%= "In Progress" %>
<%= radio_button("section", "2", "Tag2") %>
</div>
<div class="col-md-4">
<%= "Completed" %>
<%= radio_button("section", "3", "Tag3") %>
</div>
</div>
</div>
</div>
</div>
最佳答案
选项 1:检查输出的 HTML。获取 ID 并在 javascript 中使用它
选项 2:手动指定 ID,例如:<%= radio_button("development_activity", "progress", "Yet to start", :checked => true, :id => 'custom_id') %>
关于javascript - 从 JavaScript 中的 Rails 表单访问单选按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39230288/