2012-06-22 57 views
2
<table> 
    <tr><td><input type="text" value="123"></td><td><input class="here" type="text"></td></tr> 
    <tr><td><input type="text" value="333"></td><td><input class="here" type="text"></td></tr> 
</table> 

$(".here").click(function(){ 

    alert($(this).parent().before().children().val()); 

}) 

DEMO:http://jsfiddle.net/4enGp/如何使用父母,之前,孩子等?

如果我輸入點擊與類在這裏那麼這應該告訴我在這個TR第一輸入值,但是這告訴我,從電流輸入值。我怎樣才能做到這一點?

+1

你大概的意思'.prev()'乳清你說'。之前()'。 – lanzz

+0

@lanzz請添加新的答案:) –

+0

Esailija的答案實際上擊敗了我的評論幾秒鐘。 – lanzz

回答

2
jQuery(".here").click(function(){ 
    jQuery(this).parent("td").prev("td").find("input").val(); 
})​;