本文介绍了单击此图像的地图区域时获取 img 标签 ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一些像这样的地图区域的图像
并且我需要在区域区域内单击时获取图像 ID
我可以不用js实现自定义区域功能吗?
UPD
解决方案
我希望这是你正在寻找的
JS Fiddle 示例:http://jsfiddle.net/g5Dy3/44/
HTML
<img id="dotted" src="image1.jpg" usemap="#ballmap" alt="sample"/><img id="solid" src="image2" usemap="#ballmap2" alt="sample"/><地图名称=球地图"><area shape="circle" coords="210,120,90" href="#" alt="dotted ball" title="dotted ball" onclick="clickedMe(this);"></地图><地图名称="ballmap2"><area shape="circle" coords="126,90,70" href="#" alt="solid ball" title="solid ball" onclick="clickedMe(this);"></地图>
JS
function clickedMe(item) {var mapName;mapName = $(item).parent().attr('name');$('img').each(function(){if($(this).attr('usemap') == '#'+mapName){警报($(this).attr('id'));}});}
I have some images-figures with map-area like this
and i need get image id when click inside area zone
can i made it without custom area functional realisation with js?
UPD sandbox
UPD2 found second, other problem.first area zone (red), which covered by second image not clickable and z-index for area not working.
FINAL UPD
I wrote small custom function for mapping some objects.
Maybe it will help someone:
jsFiddle
解决方案
I hope this is what you are looking for
JS Fiddle Example : http://jsfiddle.net/g5Dy3/44/
HTML
<img id="dotted" src="image1.jpg" usemap="#ballmap" alt="sample" />
<img id="solid" src="image2" usemap="#ballmap2" alt="sample" />
<map name="ballmap">
<area shape="circle" coords="210,120,90" href="#" alt="dotted ball" title="dotted ball" onclick="clickedMe(this);">
</map>
<map name="ballmap2">
<area shape="circle" coords="126,90,70" href="#" alt="solid ball" title="solid ball" onclick="clickedMe(this);">
</map>
JS
function clickedMe(item) {
var mapName;
mapName = $(item).parent().attr('name');
$('img').each(function(){
if($(this).attr('usemap') == '#'+mapName){
alert($(this).attr('id'));
}
});
}
这篇关于单击此图像的地图区域时获取 img 标签 ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!