簡體   English   中英

jQuery:從單元格值獲取行

[英]Jquery: Get row from cell value

我有一個表,其中所有行都是這樣的:

<tr> 
    <td class="name">name1</td>
    <td class="type">type1</td>
    <td class="edit">
        <a href="edit" class="edit">edit</a>
    </td>
</tr>

我需要禁用某些類型的edit href。 所以我需要這樣的東西:

row = $('.mytable').find(row where .type value = type_with_no_edit) #this is where I need elp
row.find('a.edit').remove();

如果該行是第一行,那么我會這樣做:

row = $('.mytable tbody>tr:first')

但並非總是如此。

聽起來像是過濾工作...

$('.mytable tr').filter(function() {
    return $("td.type", this).text() === "type_with_no_edit";
}).find('a.edit').remove();

這發現有文本的每一行type_with_no_edit與類類型的TD與刪除TD a.edit是兄弟姐妹。

您可以使用:contains偽選擇器:

$('td.type:contains("type_with_no_edit")').siblings('.edit').empty();

演示: http//jsfiddle.net/XLwfs/

如果您不想清空TD,只需將錨定為目標並將其移除即可。

暫無
暫無

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

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