Today, when doing a project, there is the problem of removing some tr (tr is dynamically added). Try a lot of methods, are not effective (for example, the DeleteRow method, the seemingly passed parameter can only be the number of TR lines. Without careful study of the present). Later, it was noted that the method worked well and was hereby recorded.
$ (temp). Parent (). remove (); Temp for TD Id<code Class= "JS plain" > My understanding Is this: $ (temp) gets to the TD object First, then. Parent () gets to the TD tr, then remove () method, delete tr. </code>
html代码:
<table> <tr> <td><a href= ' # ' onclick= ' Removetr (this) ' >123</a></td> <td><a href= ' # ' onclick= ' Removetr (this) ' >456</a></td> </tr> <tr > <td><a href= ' # ' onclick= ' Removetr (this) ' >aaa</a></td> <td><a href= ' # ' onclick= ' Removetr (this) ' >bbb</a></td> </tr></table>
JS Code:
function Removetr (temp) { $ (temp). Parent (). Parent (). remove ();//must ensure that the page has been introduced to jquery to use //here $ (temp) first get to <a> object,. Parent () get <td>. Parent () get to TR }
jquery Removal TR