使用jquery在表中动态添加删除行
我按如下方式构建了我的表:
Name Value Scooby Doo 6
单击“添加行”按钮时,我需要将按钮更改为删除按钮并在第一行插入新行。 第一行必须包含与代码中相同的内容。 我怎样才能做到这一点?
单击删除按钮,Imust能够删除删除按钮所属的行吗?
希望这可以帮助
$(function(){ $("input[type='button'].AddRow").toggle( function(){ var el = $(this); el.closest('tr').clone(true).prependTo(el.closest('table')); el.attr("value", "Delete row"); }, function(){ $(this).closest('tr').remove(); }); }); Name Value Scooby Doo 6
工作演示
就像是?
$('#dataTable thead').prepend('Name Value ');
并删除:
$('#dataTable thead tr').click(function() { $(this).hide(); //hide the row, this doesn't delete it. });
。