编辑下面的代码:【加编码】
<html> <body> <img src="/demo/planets.gif" width="145" height="126" alt="Planets" usemap="#planetmap"> <map id="planetmap" name="planetmap"> <area shape="rect" coords="0,0,82,126" alt="Sun" href="sun.htm"> <area shape="circle" coords="90,58,3" alt="Mercury" href="mercur.htm"> <area shape="circle" coords="124,58,8" alt="Venus" href="venus.htm"> </map> <p>点击按钮获取图像地图中所有 area 元素的形状。</p> <p id="demo"></p> <button onclick="myFunction()">点我</button> <script> function myFunction() { var x = document.getElementById("planetmap"); var txt = ""; for (var i = 0; i < x.areas.length; i++) { txt = txt + x.areas[i].shape + "<br>"; } document.getElementById("demo").innerHTML = txt; } </script> </body> </html>
结果: 【此窗口】 帮助?
Try it Yourself - © 自强学堂