小码哥的IT人生

HTML DOM useMap 属性

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

HTML DOM useMap 属性

定义和用法

useMap 属性可设置或返回图像的 usemap 属性的值。

语法

imageObject.useMap=URL

实例

下面的例子可输出客户端图像映射的 usemap 属性的值:

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

TIY

完整实例【返回客户端图像映射的 usemap 属性的值】:

<html>
<body>
<img id="planets"
src="/i/eg_planets.jpg" 
usemap="#planetmap" />
<map name="planetmap">
<area
shape="circle"
coords="180,139,14"
href ="/demo/example/html/venus.html"
target ="_blank"
alt="Venus" />
</map>
<p>单击按钮以显示图像的 usemap 属性的值。</p>
<button onclick="myFunction()">试一试</button>
<p id="demo"></p>
<script>
function myFunction() {
  var x = document.getElementById("planets").useMap;
  document.getElementById("demo").innerHTML = x;
}
</script>
</body>
</html>

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

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

苏公网安备 32030202000762号

© 2021-2024