【问题标题】:Why does .hover() not work on mapped images, but .mouseover() does?为什么 .hover() 不适用于映射图像,但 .mouseover() 可以?
【发布时间】:2014-11-06 16:46:58
【问题描述】:

最近正在使用图像地图并尝试在图像地图悬停时做一些事情。当然,我首先尝试了.hover(),但没有奏效,所以当我尝试.mouseover() 时,它奏效了。

我的问题是,为什么一个有效而另一个无效?

/*This function works*/
$(document).on('mouseover', '#some-map', function(){
    console.log('I am hovering with mouseover()');
}).on('mouseout', function(){
    console.log('I am no longer hovering with mouseover()');
});

/*This function does not work*/
$(document).on('hover', '#some-map', function(){
    console.log('This is from hover()');
}, function(){
    consoel.log('Out from hover()');
});

【问题讨论】:

    标签: jquery html image imagemap


    【解决方案1】:

    jquery 中没有 on('hover' ... 方法你可以这样写

    $('#some-map').hover(function(){
       alert('This is from hover()');
    }, function(){
       alert('Out from hover()');
    });
    

    【讨论】:

    • 啊,好吧。那是有道理的。那么如何为动态创建的元素创建悬停事件呢?
    • 我以前总是这样写:
    猜你喜欢
    • 2015-05-15
    • 2016-02-15
    • 2015-06-18
    • 2018-04-16
    • 1970-01-01
    • 2014-10-26
    • 2019-03-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多