【发布时间】:2018-01-04 05:07:01
【问题描述】:
点击按钮时..部分必须显示。
$('#info_fields').html( '<%= render partial: "investor_info_fields", locals: { f: f } %>');
部分形式。
<%= f.fields_for :investor_infos do |f| %>
<div class="nested-fields">
<%= f.label :name %> <br>
<%= f.text_field :name, label: "invested companies", class: "input-md form-control mb-20" %>
<%= f.label :investment_size_id, "Investment size" %> <strong> *</strong><br>
<%= f.collection_select :investment_size_id, InvestmentSize.all, :id, :size, {}, {class: "input-md form-control mb-20 startup_info_required"} %><br>
<%= f.label :investment_time_id, "Investment time" %> <strong> *</strong><br>
<%= f.collection_select :investment_time_id, InvestmentTime.all, :id, :time, {}, {class: "input-md form-control mb-20 startup_info_required"} %><br>
</div>
<% end %>
jquery:
$(".my-class").click(function() {
var whut=$(this).val();
($(this).val() == 4) {
$('#info_fields').html( '<%= render partial: "investor_info_fields", locals: { f: f } %>');
}
});
图片:
【问题讨论】:
-
你在哪里写的这个脚本?如果它在 form_tag 之外,它将不起作用。你需要把它写在 form_tag 里面。
-
kkk.. 我写在主表单标签之外。
-
我想你在任何 ajax 请求中都有这个。这个 f 应该是表单对象。并且应该是形式。
-
同样的错误得到...我只写在表单标签内。在问题中添加了 jquery 代码 ..
-
@GaneshRaju 这不起作用,因为我可以看到您在
script块中没有f局部变量。你能说明你想做什么吗?
标签: javascript jquery ruby-on-rails ruby ruby-on-rails-5