js--根据选择不同 页面局部刷新

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<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>