我有以下型號:Ruby on Rails的 - jQuery的使用AJAX
create_table "mouldings", :force => true do |t|
t.string "suppliers_code"
t.datetime "created_at"
t.datetime "updated_at"
t.string "name"
t.integer "supplier_id"
t.decimal "length", :precision => 3, :scale => 2
t.decimal "cost", :precision => 4, :scale => 2
t.integer "width"
t.integer "depth"
end
當用戶在窗體上選擇造型我想通過Ajax獲得的成型的成本,並用它來得到一個使用JavaScript生成報價。下面是從表單中選擇標籤:
<select id="order_item_moulding_1_id" name="order_item_moulding_1[id]">
<option value="">Select a moulding 1</option>
<option value="1">123 589 698</option>
<option value="2">897 896 887</option>
<option value="3">876 234 567</option>
</select>
這裏是JavaScript文件的一部分:
$(document).ready(function() {
$('#order_item_moulding_1_id').change(function() {
var moulding_1_price = ;
});
});
如何使用Ajax來設置變量moulding_1_price?
謝謝,我使用`collection_select`來生成選擇標記。設置'data-price`屬性的正確方法是什麼? `html_options = {'data-price'=> ??? }` – freshest 2010-11-29 16:17:17