JavaScript - 获取区域地图形状的坐标

时间:2013-06-26 22:09:35

标签: javascript

我的HTML元素:

 <img src ="planets.gif" width="145" height="126" alt="Planets"
usemap="#planetmap">

<map name="planetmap">
<area shape="rect" coords="0,0,82,126" href="sun.htm" alt="Sun">
<area shape="circle" coords="90,58,3" href="mercur.htm" alt="Mercury">
<area shape="circle" coords="124,58,8" href="venus.htm" alt="Venus">
</map> 

如何使用Javascript获取coords元素中包含的每个区域形状的map

1 个答案:

答案 0 :(得分:1)

你可以试试这样的......

Live Demo

var coords = [];

[].forEach.call(document.querySelectorAll("area"), function (value, index, array) {
    coords.push(value.getAttribute("coords").split(","));
});