HTML DOM href 属性
JavaScript基础 2022-06-08 15:31:1913小码哥的IT人生shichen
HTML DOM href 属性
定义和用法
href 属性可设置或返回图像映射中链接的 URL。
语法
areaObject.href=URL
实例
下面的例子讲更改图像映射中某个区域的链接:
<html> <head> <script type="text/javascript"> function changeLink() { document.getElementById('venus').href="http://www.phpcodeweb.com" } </script> </head> <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> <input type="button" onclick="changeLink()" value="Change link" /> </body> </html>
TIY
完整实例【图像映射中某个链接的 URL】:
<html> <head> <script type="text/javascript"> function changeLink() { document.getElementById('venus').href="http://www.phpcodeweb.com" } </script> </head> <body> <p>请点击金星(Venus):</p> <img src="/i/eg_planets.jpg" usemap="#planetmap" /> <map name="planetmap"> <area id="venus" shape="circle" coords="180,139,14" href ="/demo/example/html/venus.html" alt="Venus" /> </map> <input type="button" onclick="changeLink()" value="改变链接" /> </body> </html>
可以使用本站在线JavaScript测试工具测试上述代码运行效果:http://www.phpcodeweb.com/runjs.html