我使用下面的jquery代码为我的简单发票应用程序克隆表行:我想要的是克隆tr时的2个输入字段应该为空的价格和数量,我将在此寻求帮助,在此先感谢:-
Jquery代码:
function autoCalcSetup() {
$('form[name=cart]').jAutoCalc('destroy');
$('form[name=cart] tr[name=line_items]').jAutoCalc({keyEventsFire: true, decimalPlaces: 2, emptyAsZero: true});
$('form[name=cart]').jAutoCalc({decimalPlaces: 2});
}
autoCalcSetup();
$('button[name=remove]').click(function(e) {
e.preventDefault();
var form = $(this).parents('form')
$(this).parents('tr').remove();
autoCalcSetup();
});
$('button[name=add]').click(function(e) {
e.preventDefault();
var $table = $(this).parents('table');
var $top = $table.find('tr[name=line_items]').first();
var $bottom = $table.find('tr[name=endin_colz]').first();
var $new = $top.clone(true);
$new.jAutoCalc('destroy');
$new.insertBefore($bottom);
autoCalcSetup();
});
$new.find("input").val("");
将两个输入字段都设置为空完整代码:
$('button[name=add]').click(function(e) {
e.preventDefault();
var $table = $(this).parents('table');
var $top = $table.find('tr[name=line_items]').first();
var $bottom = $table.find('tr[name=endin_colz]').first();
var $new = $top.clone(true);
$new.jAutoCalc('destroy');
$new.find("input").val("");
$new.insertBefore($bottom);
autoCalcSetup();
});
但是请注意,您的代码存在一个普遍问题-如果您克隆具有ID的元素并添加它们,则HTML不再有效,因为ID必须是唯一的。最好改用类。