简体   繁体   English

如何使用unobtrusive-ajax在ajax请求后删除DOM元素?

[英]How to remove DOM element after ajax request with unobtrusive-ajax?

In the callback function "OnSuccess",i can't get the element which i've clicked. 在回调函数“ OnSuccess”中,我无法获得单击的元素。 After click the "Del" button ,i try to remove the "tr" element which one the "Del" button in that i just clicked.how to do this? 单击“ Del”按钮后,我尝试删除我刚刚单击的“ tr”按钮中的“ tr”元素。如何执行此操作?

You can remove it using jquery: 您可以使用jquery将其删除:

$('#selector').remove();

also check this out: 还检查一下:

JavaScript DOM remove element JavaScript DOM移除元素

I use a combination of $(this) to get the button (or other dom element that triggered it). 我使用$(this)的组合来获取按钮(或触发它的其他dom元素)。

Then .closest with the tr parameter to get the row. 然后使用tr参数使用.closest来获取行。

Followed by .remove to remove it: 然后按.remove将其删除:

$(this).closest('tr').remove();

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

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