Javascript jQuery:悬停对td元素有效吗?

Javascript jQuery:悬停对td元素有效吗?,javascript,jquery,hover,html-table,Javascript,Jquery,Hover,Html Table,我有一个HTML表,其中一个td元素中有一个隐藏的信息框 <style type="text/css"> .infobox{ display: none; background-color: #FFDB8F; font-size: 11px; } td { border: 1px solid; width: 90px; height: 84px; } <

我有一个HTML表,其中一个td元素中有一个隐藏的信息框

<style type="text/css">
    .infobox{
        display: none;
        background-color: #FFDB8F;
        font-size: 11px;
    }
    td {
        border: 1px solid;
        width: 90px;
        height: 84px;
    }
</style>
<table>
    <tr>
        <td>foobar</td>
        <td>foobar</td>
        <td class="hover">hover me</td>
        <td class="hover">hover me</td>
        <td colspan="2"><div class="infobox">The terms foobar, fubar, or foo, bar, baz and qux (alternatively, quux) are sometimes used as placeholder names (also referred to as metasyntactic variables) in computer programming or computer-related documentation.</div></td>
    </tr>
    <tr>
        <td>foobar</td>
        <td>foobar</td>
        <td class="hover">hover me</td>
        <td class="hover">hover me</td>
        <td>foobar</td>
        <td>foobar</td>
    </tr>
</table>
这是:

setInterval(function() {
    var $sample = $(".hover");
    $sample.each(function(index) {
        if ($(this).is(":hover")) {
            $('.infobox').show();
        }
        else {
            $('.infobox').hide();
        }
    });
}, 200);

两者都不适用于td元素。我错过了什么?或者
.hover()
对td元素不起作用吗?

问题似乎是输入错误,您的代码上有一个额外的
}

$('.hover').hover(
    function() {$('.infobox').show();},
    function() {$('.infobox').hide();}
    } // <-- remove this
);
$('.hover').hover(
函数(){$('.infobox').show();},
函数(){$('.infobox').hide();}

}//extra
}
在您的悬停功能中。在提问之前,请查看您的控制台

$('.hover').hover(
            function() {$('.infobox').show();},
            function() {$('.infobox').hide();}
        );

查看fiddle

你不能在jQuery中访问伪类
:hover
。你必须切换一个类,如
isHovered
。问这个问题之前,你看了浏览器的控制台吗?是的,可以使用td hover-额外的括号是复制粘贴错误。这似乎是firefox的问题。好的,这似乎是firefox的问题。我做了我的代码中有一个自己的JSFIDLE,它按预期工作。如果我在浏览器中运行html文件,它将不工作。额外的}是一个复制粘贴错误。
$('.hover').hover(
            function() {$('.infobox').show();},
            function() {$('.infobox').hide();}
        );