js--根据选择不同 页面局部刷新 Posted on 2017-06-08 11:24 12345678910111213141516<div class="detail-tr form-action"> <%= f.select(:good_id, Good.where(:goods_first_category => '1').map{|g| [g.name, g.id]}, {:include_blank=>"请选择菜品用料"}, :style => 'width: 200px;') %> <%= f.text_field :amount, placeholder: '请输入菜品用量' %><p style="display:inline-block" id="material_unit"></p> <%= link_to_remove_association('删除', f, { wrapper_class: 'detail-tr' })%> <%= f.hidden_field :id %></div><script>$('#dish_materials_attributes_0_good_id(select的id)').change(function(){ id = $(this).val() $.get('/interface/goods/' + id, function(data){ $('#material_unit').text(data.unit) })})</script>