Home > Web Front-end > Front-end Q&A > What to do if jquery fails to delete tr

What to do if jquery fails to delete tr

藏色散人
Release: 2021-11-11 10:19:29
Original
2393 people have browsed it

The solution to the failure of jquery to delete tr: 1. Get the td object first through "$(temp)"; 2. Get the tr of td through ".parent()"; 3. Use "remove" ()" method to delete tr.

What to do if jquery fails to delete tr

The operating environment of this article: windows7 system, jquery version 1.2.6, DELL G3 computer

What should I do if jquery fails to delete tr?

jQuery’s invalid solution for removing tr (tr is dynamically added)

When I was working on a project today, I encountered a problem, that is, removing certain tr (tr is dynamically added). I have tried many methods, but none of them work (for example, in the deleteRow method, it seems that the parameter passed can only be the number of rows of tr. I have not studied it carefully so far). Later, I found that this method worked well, so I will record it here.

$(temp).parent().remove(); //temp为td的id 
<code class="js plain"> 
我的理解是这样的:$(temp)先获取到该td对象,然后.parent()获取到td的tr,再remove()方法,删除tr。</code>
Copy after login

html code:

<table> 
<tr> 
<td><a href=&#39;#&#39; onclick=&#39;removeTr(this)&#39;>123</a></td> 
<td><a href=&#39;#&#39; onclick=&#39;removeTr(this)&#39;>456</a></td> 
</tr> 
<tr> 
<td><a href=&#39;#&#39; onclick=&#39;removeTr(this)&#39;>aaa</a></td> 
<td><a href=&#39;#&#39; onclick=&#39;removeTr(this)&#39;>bbb</a></td> 
</tr> 
;/table>
Copy after login

js code:

function removeTr(temp){ 
mp).parent().parent().remove(); //必须保证页面已经引入了jQuery才可以使用 
//此处$(temp)先获取到<a>对象,.parent()拿到<td>,再.parent()获取到tr 
}
Copy after login

Recommended learning: "jquery video tutorial"

The above is the detailed content of What to do if jquery fails to delete tr. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template