2009-09-17 54 views
0

如何处理当前未选中的元素。例如,在我的HTML文件,我有如何处理不包括在jquery中选择的元素

<table> 
    <tr><td> .... </tr></td> 
    <tr><td> .... </tr></td> 
    <tr><td> .... </tr></td> 
    <tr><td> .... </tr></td> 
</table> 

的js文件, 我有一个click事件,并选择该行之一。在此事件触发期间,我想处理其他行。

$("table tr").click(function(){ 
    // process the unselected rows here such as change the background color... 
}); 

回答

2

看看siblings function

然后,它会在点击功能:

$(this).siblings(); 
+0

漂亮的直线前进。我从来没有在Jquery.com文档中看到这一点 – kratz 2009-09-17 14:01:53

0

+1 fphilipe's answer,虽然是东西的样式的逻辑应该被反转 - 即你应该风格选定的行,而不是处理其他行。

$("table tr").click(function() { 
    $(this) 
     .siblings().removeClass('selected').end() 
     .addClass('selected'); 
}); 

而CSS

.selected { background-color: #D6E4EE; }