簡體   English   中英

用類刪除父元素

[英]Remove parent element with class

我有以下的HTML結構...

  <tr class="table_opening_CL">
    <td>
  <button class="extract_bt">Approve</button>
  <button class="extract_bt">Delete</button><br>
  <input name="featured" class="featured_selector" type="checkbox" />
  Featured<input name="public_selector" class="public_selector" type="checkbox" />
  Public
   </td> 
        <td>25</td> 

        <td>Session</td> 

        <td>Beek</td> 

        <td>dPC7t</td> 
        <td>2012-01-27 23:38:19</td> 
        <td>Abstract</td> 

        </tr>       

現在我使用類extract_bt將click事件綁定到button ...

在click事件上,如果響應為true,我將向服務器發布一些數據,那么我也需要使用table_opening_CL類及其內部HTML刪除元素TR

我提醒了$(this).html(); .post內部,但返回NULL

確實,我們需要存儲this發布之前?

請幫我

謝謝。

更新:

這是我使用的代碼...

 $(".extract_bt").live('click',function(){
var p_key = $(this).parent().next().next().next().next().text();
var p_id = $(this).parent().next().text();
var fchkd = $(this).parent().find(".featured_selector").prop("checked");
var pchkd = $(this).parent().find(".public_selector").prop("checked");

$.post("url",{PACKAGE_KEY:p_id,FEATURED:fchkd,PUBLIC:pchkd,PACKAGE:p_key},function(data){
  if (data)
  {
  alert($(this).html());
     $(this).parents(".table_opening_CL").remove();
  }
  else 
  {
    alert(data);
  }

  },"json");
});    
});

是的,在成功post處理程序中, this不會指向DOM元素,因此$(this).html()將無法工作。

我認為您正在尋找類似的東西。

$('.extract_bt').click(function(){
   var $btn = $(this);
    $.post("urlOfThePage", {}, function(response){
         //If reponse will be boolean you can just say if(response)
         if(response == true){
            //This will remove the whole tr element including child elements.
            $btn.closest('tr.table_opening_CL').remove();
         }
    }
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM