jQuery移除tr,jquerytr

來源:互聯網
上載者:User

jQuery移除tr,jquerytr

        今天在做項目時,碰到一個問題,那就是移除掉某些tr(tr是動態添加的)。嘗試了很多方法,都不見效(比如,deleteRow方法,貌似傳的參數只能是tr的行數。沒有仔細研究目前)。後來,發現這個方法效果不錯,特此記錄。

    $(temp).parent().remove(); //temp為td的id<code class="js plain">     我的理解是這樣的:$(temp)先擷取到該td對象,然後.parent()擷取到td的tr,再remove()方法,刪除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代碼:  

         function removeTr(temp){    $(temp).parent().parent().remove(); //必須保證頁面已經引入了jQuery才可以使用               //此處$(temp)先擷取到<a>對象,.parent()拿到<td>,再.parent()擷取到tr         }




 

     


jquery 怎刪除當前點擊的tr 我點擊 td裡面的資料,怎擷取當前點擊的td上一個tr哪個一行

<tr id="del">
<td>1</td>
</td>2</td>

</tr>
如何點擊刪除tr:
$(function(){
$("#del").click(function(){
$(this).remove();

});

})

至於後面td操作不是很明白,希望樓主下次問問題之前把問題表述清楚
 
jquery 怎刪除當前點擊的tr 我點擊 td裡面的資料,怎擷取當前點擊的td上一個tr哪個一行

<tr id="del">
<td>1</td>
</td>2</td>

</tr>
如何點擊刪除tr:
$(function(){
$("#del").click(function(){
$(this).remove();

});

})

至於後面td操作不是很明白,希望樓主下次問問題之前把問題表述清楚
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.