Jquery:图像地图区域上的鼠标悬停事件
我正在尝试对图像地图区域的鼠标悬停执行操作。这是我的 HTML:
<img src="img/denisanddavid-bkgd.jpg" alt="Denis and David - web development and solution" width="1024" height="1299" border="0" usemap="#bkgdMap" id="bkgd" />
<map name="bkgdMap" id="bkgdMap">
<area shape="rect" coords="12,161,341,379" href="#" alt="qdk" id="qdk" class="mapping" />
<area shape="rect" coords="347,162,675,379" href="#" alt="gifgif" alt="gifgif" class="mapping" />
</map>
这是我的 js:
$('.mapping').mouseover(function() {
alert($(this).attr('id'));
}).mouseout(function(){
alert('Mouseout....');
});
我不明白为什么,但是 jquery 仅针对第一个区域启动,而不是其他区域。任何帮助将不胜感激。
谢谢。
I'm trying to do actions on mouseover of an image map area. Here is my HTML:
<img src="img/denisanddavid-bkgd.jpg" alt="Denis and David - web development and solution" width="1024" height="1299" border="0" usemap="#bkgdMap" id="bkgd" />
<map name="bkgdMap" id="bkgdMap">
<area shape="rect" coords="12,161,341,379" href="#" alt="qdk" id="qdk" class="mapping" />
<area shape="rect" coords="347,162,675,379" href="#" alt="gifgif" alt="gifgif" class="mapping" />
</map>
And here is my js:
$('.mapping').mouseover(function() {
alert($(this).attr('id'));
}).mouseout(function(){
alert('Mouseout....');
});
I don't understand why, but the jquery is only launched for the first area and not the others. Any help would be greatly appreciated.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我刚刚在 Safari 中尝试了你的代码,它按预期工作。 2 个发出单独警报的独立区域。一个是警告“qdk”,另一个是“未定义”,因为您没有第二张地图的 ID 属性。
I just tried your code in Safari and it works just as intended. 2 separate areas that give out separate alerts. One is alerting "qdk" and other "undefined", as you don’t have an ID attribute for the second map.
您尝试过使用悬停吗?
来自 jquery 网站的示例...
Did you try using hover?
example from jquery site...