简体   繁体   English

JavaScript - 点击jQuery无法正常工作?

[英]JavaScript - jQuery on click doesn't work correctly?

I have a Sweetalert plugin in use. 我有一个Sweetalert插件正在使用中。 I made there an table with an X button, after you click button then the sweetalert pops up with table content and the X's. 我在那里制作了一个带有X按钮的桌子,点击按钮后,sweetalert弹出表格内容和X. So I made code, if you click on X it will delete it from the table, but it won't work for me.. If I copied the SweetAlert HTML code to JSFiddle and the same deleting code, then it was working. 所以我创建了代码,如果你单击X它将从表中删除它,但它对我不起作用..如果我将SweetAlert HTML代码复制到JSFiddle和相同的删除代码,那么它正在工作。

$('.sweet-container').on('click', 'tr td span', function(){
    $(this).closest('tr').remove();
});

I came across with the similar problem in the past. 我过去遇到过类似的问题。 Your trigger is created before the .sweet-container is created in DOM You can use http://api.jquery.com/delegate/ . 您的触发器是在DOM中创建.sweet-container之前创建的。您可以使用http://api.jquery.com/delegate/

$('.sweet-container').delegate('tr td span', 'click', function(){
    $(this).closest('tr').remove();
});

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

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