Change background color on mouseover and remove it after mouseout

前端 未结 7 1113
被撕碎了的回忆
被撕碎了的回忆 2020-12-05 10:38

I have table which class is forum. My jquery code:



        
7条回答
  •  春和景丽
    2020-12-05 10:57

    Set the original background-color in you CSS file:

    .forum{
        background-color:#f0f;
    }​
    

    You don't have to capture the original color in jQuery. Remember that jQuery will alter the style INLINE, so by setting the background-color to null you will get the same result.

    $(function() {
        $(".forum").hover(
        function() {
            $(this).css('background-color', '#ff0')
        }, function() {
            $(this).css('background-color', '')
        });
    });​
    

提交回复
热议问题