2011-11-01 38 views

回答

14

此:

var prevRow = row.previousElementSibling; 

var prevRow = $(row).prev()[0]; 

[0]是用來 「解包jQuery對象」,以獲取DOM引用該行如果要執行jQuery方法。那行,你可以把它留在裏面,就像$(row).prev().addClass('...');那樣,你不需要一個新的變量。)

2

假設這兩行是兄弟姐妹(不包括獨立非執行董事在單獨tbodythead元素):

$curRow = $(this); // or however you're getting the current `tr`. 
$curRow.prev('tr'); 

應該讓你的上一行。

1

那麼你需要做的是,像這樣:

$("#cellID").parent().prev()

1

您的意見是不夠的,但如果我正確地理解這裏是你的要求代碼..

If your Variable contains table row id then $('#yourVariableName').prev('tr')[0] will work. 
If your Variable contains table row Class then $('.yourVariableName').prev('tr')[0] will work. 
If your Variable contains table row index then $(' table tr').eq(varValue).prev('tr')[0] will work. 

但請指定你的變量將包含什麼。

1

比方說,你想在目前的一個以上的TR從TD的輸入值:

$('#id').prev().children('td').children(':text').val(); 
相關問題