jQuery在表的悬停效果 [英] jQuery hover effect over table

查看:124
本文介绍了jQuery在表的悬停效果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新的jQuery,我想在我的表上做悬停效果,但我不知道如何。
我想只使文本为红色,然后在焦点丢失时如何重新删除红色。

I am new to jQuery and I am trying to make a hover effect on my table but I don't know how. I would like to make only the text red and then how to remove the red color again when the focus has been lost.

这是我的far:

<script type="text/javascript">
$(function() {
    $('tr').hover(function() {
        $(this).css('color', 'red')
    });
});
</script>


<table border="1">
    <tr>
        <th>ID</th>
        <th>name</th>
    </tr>
    <tr>
        <td>#1</td>
        <td>ole</td>
    </tr>
    <tr>
        <td>#2</td>
        <td>jeffrey</td>
    </tr>
    <tr>
        <td>#3</td>
        <td>collin</td>
    </tr>
    <tr>
        <td>#4</td>
        <td>eve</td>
    </tr>
</table>


推荐答案

所有你需要做的是将另一个函数传递给hover

All you need to do is pass another function to hover for the mouse leave.

$('tr').hover(function() {
    $(this).css('color', 'red');
}, function() {
    $(this).css('color', '');
});

请参阅 jsfiddle

或者您也可以在css中执行。

Or you could do it only in css as well.

tr:hover{
    color:red;
}




IE 5/6只支持链接。 IE
7支持:hover,但不是:active,on
所有元素。
此处

这篇关于jQuery在表的悬停效果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆