我正在尝试从主视图表单执行 JavaScript,当我单击渲染部分中的复选框时,从渲染部分执行 JavaScript,但 JavaScript 不执行。仅当我在主视图中复制部分内容时才会执行。我已经搜索了该网站,但我无法得到答案。这就是我所拥有的,例如:
app/views/people/_main_form.html.erb
<script>
view something in partal
$('people_visible_by_default').click(function(){
alert("Can you see me");
});
</script>
<%= bootstrap_nested_form_for @people, html: { class: 'form-horizontal', id: 'people_edit_form' } do |f| %>
<%= render partial: 'form_partial', locals: { f: f } %>
<% end %>
在 app/views/people/_form_partial.html.erb 中执行的复选框
<%= f.check_box :visible_by_default, data: { preview_type: 'none' } %>
clicking on the visible_by_default checkbox doesn't show the alert as I expected. How do I get it to execute when it is in the main_form.html.erb