2012-02-07 77 views
1

我需要它,因此當您單擊表格行時,它僅突出顯示錶格中的一行,如果用戶要從同一個表格中單擊另一個TR,它將取消選擇先前選擇的TR並突出顯示點擊的一個。僅在表格中突出顯示一個<tr>

幫助?

什麼現在使用im是

<tr onclick="style.backgroundColor='#eaf0f5';"> ..... </tr> 
+0

你還嘗試過什麼嗎?你的代碼在哪裏? – gonchuki 2012-02-07 11:40:57

+0

當下我所擁有的就是onclick =「style.backgroundColor ='#eaf0f5';」裏面的 – ahmet 2012-02-07 11:42:31

+0

使用jQuery。這裏你有api文檔:http://api.jquery.com/ 你可能想看看選擇器:) – 2012-02-07 11:42:57

回答

6

試試這個:

jQuery的1.7+

$("table tr").on('click', function() { 
    $("table tr").removeClass("highlight"); 
    $(this).addClass("highlight"); 
}); 

jQuery的< 1.7

$("table tr").click(function() { 
    $("table tr").removeClass("highlight"); 
    $(this).addClass("highlight"); 
}); 

CSS

.highlight { background-color: #FF0; } 
+0

未捕獲TypeError:對象[對象對象]沒有方法 – ahmet 2012-02-07 11:52:19

+0

我想你正在使用舊版本的jQuery,我會更新我的答案。 – 2012-02-07 11:52:57

+0

現在感謝沒有錯誤,但是當我點擊一個TR時,它將我導航到另一個標籤,因爲它應該,但是當我回到原始選項卡時,它不會突出顯示,我的.highlight在我的css – ahmet 2012-02-07 11:55:07