Sort table using tablesorter and change background on hovering the even and odd rows

北战南征 提交于 2019-12-13 04:37:51

问题


http://jsfiddle.net/6ecr4/8/

$(document).ready(function () {
    $(".items").tablesorter();
    $('.items tr:even').addClass('ItemEvenRow');

    $('.items tr').hover(function () {
        $(this).addClass("ItemRowHover");
    }, function () {
        $(this).removeClass("ItemRowHover");
    });
});

HTML :

<table class="items"> 
<thead> 
<tr class=""> 
    <th>Last Name</th> 
    <th>First Name</th> 
    <th>Email</th> 
    <th>Due</th> 
    <th>Web Site</th> 
</tr> 
</thead> 
<tbody> 
<tr> 
    <td>Smith</td> 
    <td>John</td> 
    <td>jsmith@gmail.com</td> 
    <td>$50.00</td> 
    <td>http://www.jsmith.com</td> 
</tr> 
<tr>  
    <td >Bach</td> 
    <td >Frank</td> 
    <td >fbach@yahoo.com</td> 
    <td >$50.00</td> 
    <td >http://www.frank.com</td> 
</tr> 
<tr > 
    <td  >Doe</td> 
    <td >Jason</td> 
    <td>jdoe@hotmail.com</td> 
    <td  >$100.00</td> 
    <td>http://www.jdoe.com</td> 
</tr> 
<tr> 
    <td>Conway</td> 
    <td>Tim</td> 
    <td>tconway@earthlink.net</td> 
    <td>$50.00</td> 
    <td>http://www.timconway.com</td> 
</tr> 
</tbody> 
</table> 

The even rows do not possess the hover, but only the odd ones. Require both, even, as well as, odd rows to change their background on mouse-over. The headers should be as they are without any changes.


回答1:


The hover isn't working on even rows because of css precedence. Make the selector more specific like this (add a tr in front; updated demo):

tr.ItemRowHover  {background-color:#A00000; }


来源:https://stackoverflow.com/questions/20797765/sort-table-using-tablesorter-and-change-background-on-hovering-the-even-and-odd

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!