简体   繁体   English

jQuery如何删除动态附加的行?

[英]jQuery how to remove dynamically appended rows?

If I append rows to my table like this: 如果我将行追加到表中,如下所示:

 $('#tbody_upload').append('<tr id="' + data.originalFiles[counter].name + '"><td>' + 'Uploading...' + '</td><td></td><td></td><td></td></tr>');

how can I remove it from another event? 如何将其从另一个事件中删除?

$('#' + this.name).remove();

that function doesn't work, also appended items don't appear in source of the page. 该功能不起作用,附加的项也不会出现在页面源中。

If you want remove the element that triggers the event to be removed (as appears from this.name) you can simply do 如果要删除触发事件被删除的元素(如this.name所示),则只需执行

$(this).remove(); $(this).remove();

Maybe you should name your table and then with a selector select the body and first errase it and then append data so every time you get new data, the table deletes the old data and puts the new one. 也许您应该命名表,然后使用选择器选择主体,然后先擦除它,然后追加数据,以便每次获取新数据时,该表都会删除旧数据并放入新数据。

<table id="yourtableName" border="1" class="hoverTable">
<thead>

</thead>
<tbody>
</tbody>
</table>

var gridBody = your tr code; var gridBody =您的tr代码;

$('#yourtableName tbody').empty().append(gridBody);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM