Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
jQuery:为什么这个元素不会隐藏在悬停状态?_Jquery_Hover_Hide_Element - Fatal编程技术网

jQuery:为什么这个元素不会隐藏在悬停状态?

jQuery:为什么这个元素不会隐藏在悬停状态?,jquery,hover,hide,element,Jquery,Hover,Hide,Element,现在这真的令人沮丧 我创建了一个脚本,当您悬停一个特殊链接时,它会将另一个页面的一些内容附加到正文中。我还将其设置为每当我将鼠标移离链接时,新元素(包含加载的内容)都会隐藏。到目前为止,一切顺利。问题是,有时当我将光标移离链接太快时,脚本不会做出反应(或其他)。啊,好吧,我想,刚刚添加了这个拒绝工作的邪恶代码: $('#userBubble').mouseover(function() { $(this).hide(); }); 现在,这有什么问题吗?我试过用mouseenter来代替

现在这真的令人沮丧

我创建了一个脚本,当您悬停一个特殊链接时,它会将另一个页面的一些内容附加到正文中。我还将其设置为每当我将鼠标移离链接时,新元素(包含加载的内容)都会隐藏。到目前为止,一切顺利。问题是,有时当我将光标移离链接太快时,脚本不会做出反应(或其他)。啊,好吧,我想,刚刚添加了这个拒绝工作的邪恶代码:

$('#userBubble').mouseover(function() {
    $(this).hide();
});
现在,这有什么问题吗?我试过用mouseenter来代替,但也没有成功。我还尝试将它放在$(document).ready()函数中-也没有运气#userBubble是hover上加载的内容的容器,名称正确。我可以console.log#userBubble,所以它确实存在

知道是什么搞砸了吗?我没有错误,只是不起作用。

你试过这个吗

$('#userBubble').mouseover(function(event) {

        $(event.target).hide();

});
编辑:哦,你的问题读得不太好。
就像斯皮尼·诺曼(Spiny Norman)说的,你必须使用“live”或“delegate”;)

你试过这个吗

$('#userBubble').mouseover(function(event) {

        $(event.target).hide();

});
编辑:哦,你的问题读得不太好。

就像斯皮尼·诺曼(Spiny Norman)说的,你必须使用“live”或“delegate”;)

确保用户ID在DOM中是唯一的,并且绑定时元素存在(或使用
live

将其更改为类并使用live。我敢打赌它一定有用

<img id="userBubble" class="userBubble"/>

$('.userBubble').live("mouseover", function() {
    $(this).hide();
});

$('.userBubble').live(“鼠标悬停”,函数(){
$(this.hide();
});

确保用户ID在DOM中是唯一的,并且绑定时元素存在(或使用
live

将其更改为类并使用live。我敢打赌它一定有用

<img id="userBubble" class="userBubble"/>

$('.userBubble').live("mouseover", function() {
    $(this).hide();
});

$('.userBubble').live(“鼠标悬停”,函数(){
$(this.hide();
});

这可能是因为添加处理程序时元素还不存在。试一试

$('#userBubble').live('mouseover', function() {
   $(this).hide();
});

相反。

这可能是因为添加处理程序时元素还不存在。试一试

$('#userBubble').live('mouseover', function() {
   $(this).hide();
});

相反。

在设置事件之前,请确保已加载html div:

 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            $('#test').mouseover(function () { $(this).hide(); })
        });
    </script>
</head>
<body>
    <div id="test">This will hide!</div>
</body>
</html>

$(文档).ready(函数(){
$('#test').mouseover(函数(){$(this.hide();})
});
这会藏起来的!

在设置事件之前,请确保已加载html div:

 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            $('#test').mouseover(function () { $(this).hide(); })
        });
    </script>
</head>
<body>
    <div id="test">This will hide!</div>
</body>
</html>

$(文档).ready(函数(){
$('#test').mouseover(函数(){$(this.hide();})
});
这会藏起来的!
它与hover一起工作

$('#userBubble').hover(function() {
    $(this).hide();
});
它与hover一起工作

$('#userBubble').hover(function() {
    $(this).hide();
});

以下方法应该有效


$(document).ready( function()
{
    $("#hoverHide").mouseover( function ()
    {
        $(this).hide();
    } );
} );
如果不起作用,请尝试以下操作:


$(document).ready( function()
{
    $("#hoverHide").mouseover( function ()
    {
        $("#hoverHide").hide();
    } );
} );

如果这两种方法都不起作用,那么您的页面上可能有语法错误。可能在
.ready
函数声明中。

以下操作应该有效


$(document).ready( function()
{
    $("#hoverHide").mouseover( function ()
    {
        $(this).hide();
    } );
} );
如果不起作用,请尝试以下操作:


$(document).ready( function()
{
    $("#hoverHide").mouseover( function ()
    {
        $("#hoverHide").hide();
    } );
} );

如果这两种方法都不起作用,那么您的页面上可能有语法错误。可能在
.ready
函数声明中。

页面上有多少
id=“userBubble”
元素?请提供更多代码。我不确定你的第一段。“你有一个链接到那个页面,把事情搞砸了吗?”尼克,一个。我知道不能有几个元素具有相同的id。@Blank,我正在本地运行它。如果无法修复,我可能会发布整个页面。页面上有多少
id=“userBubble”
元素?请提供更多代码。我不确定你的第一段。“你有一个链接到那个页面,把事情搞砸了吗?”尼克,一个。我知道不能有几个元素具有相同的id。@Blank,我正在本地运行它。如果我想不出如何修复的话,我可能会发布整个页面。是的,就是这样。该ID已经是唯一的,但在将其更改为live()后,它仍然有效。谢谢一群人!是的,就是这样。该ID已经是唯一的,但在将其更改为live()后,它仍然有效。谢谢一群人!