2015-04-03 78 views
-1

我試圖搜索具有由另一個函數動態創建的userName的特定行,並將其從表中刪除。但我現在能夠搜索該行。
這是怎麼了加入新行:
搜索動態創建的行並刪除

$("table").append("<tr><td>" + userName + "</td></tr>"); 

,這是我正在尋找該表具有userName和取出該行:

$("table").find("<tr><td>" + userName + "</td></tr>").remove(); 

回答

1

的參數find是一個選擇器,而不是HTML。

$("table").find("td:contains("+userName+")").remove(); 
0

您可以使用功能選擇,請參見下面的示例代碼

$("table").find("tr > td:contains('"+ userName +"')").remove(); 
1

使用基於選擇

$('table td:contains('+userName+')').remove() 

$('table').find('td:contains('+userName+')').remove() 

Fiddle

您的代碼不是找到現有DOM孩子的正確方法。

完全匹配使用.filter()

$("table td").filter(function() { 
    return $(this).text() === userName; 
}).remove() 
0

即使您嘗試使用jQuery最接近的一次。

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