1

http://jsfiddle.net/twkRY/

<table>
    <tr>
        <td class="iwant">ttt</td>
        <td>some text <span class="txt">haha</span></td>
    </tr>
</table>

$(".txt").on("click", function() {
    alert($(this).closest("td.iwant").html())
})

它只是给出未定义的。为什么不ttt

编辑:我知道如何使它工作的解决方案prevparent我只想知道为什么closest不起作用。

4

1 回答 1

1

你想得到closest td,然后用 . 得到前一个兄弟姐妹prev

$(this).closest("td").prev(".iwant").html()
于 2013-07-27T17:15:31.287 回答