Jquery 动态按钮不适用于动态表

Jquery 动态按钮不适用于动态表,jquery,jquery-selectors,Jquery,Jquery Selectors,我有一张桌子和一个“空”按钮。单击“清空”后,表将消失。另一个按钮“新建”,单击后,将创建一个新表。 按钮和桌子都在一个名为“稳定”的div下。但是如果我先清空,然后创建新表,按钮清空。按钮是空的,不起作用。有什么建议吗?拨弄 序列号 个人的 营销点 添加/删除 JS文件如下: $('.addnew').live('click', function(){ var thisRow = $(this).parent().parent(); newRow = thisRow.clo

我有一张桌子和一个“空”按钮。单击“清空”后,表将消失。另一个按钮“新建”,单击后,将创建一个新表。 按钮和桌子都在一个名为“稳定”的div下。但是如果我先清空,然后创建新表,按钮清空。按钮是空的,不起作用。有什么建议吗?拨弄


序列号
个人的
营销点
添加/删除
JS文件如下:

$('.addnew').live('click', function(){
    var thisRow = $(this).parent().parent();
    newRow = thisRow.clone(true).insertAfter(thisRow);
    newRow.find('input:not(.add)').val("");

    $(this).removeClass('addnew').addClass('remove');
    $(this).val("-");
    newRow.find('input.increment').val(parseInt(thisRow.find('input.increment').val())+1);
});

$('.remove').live('click', function(){
    $(this).parent().parent().remove();
});

$('#sTable .submit').click(function(){
        $("#tbl").empty();
    //$(' .even').css('background-color', 'blue');
});
$('.create').click(function(){
var t = "<table width='100%' id='tbl'><tr><th></th><th>Serial No</th><th>Personale</th><th>Marketing point</th><th >Add/Remove</th></tr>"
t +="<tbody><tr class='even'>"
t +="<td><input type='text' name='serial[]'  class='add increment' value='1'  size='2%' ></td>"
t +="<td><input type='text' value='' name='Personale[]'  size='2%'></td>"
t +="<td><input type='text' class='totaliCostiGestione' name='marketpt[]'></td>"
t +="<td><input type='text' name='programid[]' class='add' value='34' size='10%'></td>"
t +="<td><input type='button' class='addnew add' value='+' /></td></tr>"
t +="<tr><td colspan='5'><input type='submit' name='submit' value='Empty' class='submit'></td>"
t +="</tr></tbody></table>"
$("#sTable").append(t);
$('.addnew').live('click',function()){
var thisRow=$(this.parent().parent();
newRow=thisRow.clone(true).insertAfter(thisRow);
newRow.find('input:not(.add')).val(“”);
$(this.removeClass('addnew').addClass('remove');
$(此).val(“-”);
newRow.find('input.increment').val(parseInt(thisRow.find('input.increment').val())+1);
});
$('.remove').live('单击',函数()){
$(this.parent().parent().remove();
});
$('#sTable.submit')。单击(函数(){
$(“#tbl”).empty();
//$('.even').css('background-color','blue');
});
$('.create')。单击(函数(){
var t=“序列号个人营销点添加/删除”
t+=“”
t+=“”
t+=“”
t+=“”
t+=“”
t+=“”
t+=“”
t+=“”
$(“#稳定”)。追加(t);

创建动态内容时,您可以使用

在本例中,首先需要获取包含
空按钮的表

更改此项:

$('#sTable .submit').click(function(){
        $("#tbl").empty();
    //$(' .even').css('background-color', 'blue');
});
对此

$('#sTable').on("click", ".submit", function () {
    $(this).parents("#tbl").empty();
});

您使用的是哪个jquery版本???创建了fiddle文件。非常感谢。如果我有一个像$('#sTable tbody tr').each(function(){})这样的函数,我如何将委托与on()一起使用?这将取决于您试图在其中执行的操作,如果您愿意,可以为此创建另一个问题
$('#sTable').on("click", ".submit", function () {
    $(this).parents("#tbl").empty();
});