小码哥的IT人生

HTML DOM coords 属性

JavaScript基础 2022-06-08 15:28:14小码哥的IT人生shichen

HTML DOM coords 属性

定义和用法

coords 属性设置或返回一个逗号分隔列表,其中包含了图像映射中一个链接的坐标。

语法

anchorObject.coords=coordinates

实例

下面的例子可返回图像映射中一个链接的坐标:

<html>
<body>
<img src="planets.gif" 
width="145" height="126" 
usemap="#planetmap" />
<map name="planetmap">
<area id="venus" shape="circle" 
coords="124,58,8" 
alt="Venus"
href="venus.htm" />
</map>
<p>Venus coordinates:
<script type="text/javascript">
x=document.getElementById("venus");
document.write(x.coords);
</script>
</p>
</body>
</html>

TIY

完整实例【取得图像映射中一个链接的坐标】:

<html>
<body>
<img src="/i/eg_planets.jpg" 
usemap="#planetmap" />
<map name="planetmap">
<area id="venus" shape="circle" 
coords="180,139,14" 
alt="Venus"
href="/demo/example/hdom/venus.html" />
</map>
<p>Venus 的坐标(coords 属性)是:
<script type="text/javascript">
x=document.getElementById("venus");
document.write(x.coords);
</script>
</p>
</body>
</html>

可以使用本站在线JavaScript测试工具测试上述代码运行效果:http://www.phpcodeweb.com/runjs.html

版权所有 © 小码哥的IT人生
Copyright © phpcodeweb All Rights Reserved
ICP备案号:苏ICP备17019232号-2  

苏公网安备 32030202000762号

© 2021-2024