【发布时间】:2016-08-24 10:40:10
【问题描述】:
如何在 jQuery .after() 中的 html name="" 中增加一个数组?
像这样
$(document).ready(function() {
$('#add_products').click(function() {
$('.products_tr:last').after('<tr class="products_tr"><td><input id="quantity" class="form-control" type="text" value="" name="invoice[products_attributes][1][quantity]"></td></tr>');
});
});
它应该向发票中添加额外的行,并且它可以正常工作,但为了将其正确保存到数据库中,name="invoice[products_attributes][1][quantity] 中的“[1]”需要增加。它需要根据最后一个值递增。
顺便说一句,该代码是由 Ruby On Rails 动态创建的。
有人知道实现此目的的方法吗?帮助将不胜感激!
【问题讨论】:
-
'...name="invoice[products_attributes]['+ a value+'...'
标签: javascript jquery html ruby-on-rails