我試圖搜索具有由另一個函數動態創建的userName
的特定行,並將其從表中刪除。但我現在能夠搜索該行。
這是怎麼了加入新行:
搜索動態創建的行並刪除
$("table").append("<tr><td>" + userName + "</td></tr>");
,這是我正在尋找該表具有userName
和取出該行:
$("table").find("<tr><td>" + userName + "</td></tr>").remove();
我試圖搜索具有由另一個函數動態創建的userName
的特定行,並將其從表中刪除。但我現在能夠搜索該行。
這是怎麼了加入新行:
搜索動態創建的行並刪除
$("table").append("<tr><td>" + userName + "</td></tr>");
,這是我正在尋找該表具有userName
和取出該行:
$("table").find("<tr><td>" + userName + "</td></tr>").remove();
的參數find
是一個選擇器,而不是HTML。
$("table").find("td:contains("+userName+")").remove();
您可以使用功能選擇,請參見下面的示例代碼
$("table").find("tr > td:contains('"+ userName +"')").remove();
使用基於選擇
$('table td:contains('+userName+')').remove()
或
$('table').find('td:contains('+userName+')').remove()
您的代碼不是找到現有DOM孩子的正確方法。
完全匹配使用.filter()
,
$("table td").filter(function() {
return $(this).text() === userName;
}).remove()
即使您嘗試使用jQuery最接近的一次。
$('table').closest('tr').remove();