[英]Remove Button to configure in Table (editable) cloned rows
I have an editable table with rows cloned , the rows cloned are editable in both column with a text area and input number . 我有一个可编辑的表,其中包含已克隆的行,已克隆的行在带有文本区域和输入数字的两列中都是可编辑的。 If you click to edit the input number, there is a function which makes the sum and gives the Total Amount automatically.
如果单击以编辑输入数字,则有一个功能可以求和并自动给出总金额。
My issue now is that i can not configure properly the remove button for the rows cloned. 我现在的问题是我无法为克隆的行正确配置删除按钮。 If you give a try you notice that instead of removing a row, it adds one more.
如果您尝试一下,您会发现它不会删除一行,而是会添加一行。 Please i need help on how to figure it out this issue.
请我需要有关如何解决此问题的帮助。
This is the script for rows cloned, i think it needs to get reduced and improved 这是克隆行的脚本,我认为需要减少和改进
$('input:button').live('click',function(){
var temprow = $('#temprow tbody').html();
var tr = $(this).closest('tr');
tr.after(temprow);
});
$("input.tr_clone_add").live('click', function() {
var lastid = $('[id^="sum"]').length + 1;
var $tr = $(this).closest('.tr_clone');
var $clone = $tr.clone();
$clone.find(':text').val('');
$clone.attr('id', 'sum' + lastid)
$tr.after($clone);
initEditables();
tally('p#subtotal');
tally('p#total');
});
$(".tr_clone_remove").live("click", function() {
$(".tr_clone").last().remove();
initEditables();
tally('p#subtotal');
tally('p#total');
});
initEditables();
tally('p#subtotal');
tally('p#total');
Edited your Fiddle with the correct solution: http://jsfiddle.net/Manna/S3kZw/5/ 使用正确的解决方案编辑了Fiddle: http : //jsfiddle.net/Manna/S3kZw/5/
Since the tr_clone_remove
class is also a button type input, the first handler is called every time you click on the remove button. 由于
tr_clone_remove
类也是按钮类型的输入,因此,每当您单击remove按钮时,都会调用第一个处理程序。
$('input:button').live('click',function(){ var temprow = $('#temprow tbody').html(); var tr = $(this).closest('tr'); tr.after(temprow); });
This is the reason why rows are being inserted, instead of being deleted. 这就是为什么要插入行而不是删除行的原因。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.