gpt4 book ai didi

jquery - 监听添加的表行

转载 作者:行者123 更新时间:2023-12-03 23:00:52 55 4
gpt4 key购买 nike

假设我有一张 table :

<table>
<tr></tr>
</table>

$(function(){

$('#btn').click(function(){
$('table').append('<tr><input class="remove" value="remove"></tr>');
});

$('.remove').on('click', function(){

$(this).parent().remove();
});

});

是否有任何方法可以使用 jQuery 绑定(bind)自定义事件处理程序,该处理程序在添加或删除行时触发?

谢谢

最佳答案

是的,您可以绑定(bind)自定义事件。

$('#table_id').bind('rowAddOrRemove', function(event){
//do what you want.
});

当您添加或删除行时,您应该触发该事件。

$('#table_id').trigger('rowAddOrRemove');

关于jquery - 监听添加的表行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9095472/

55 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com