取代.参考这个标题

Replace this.href with this.title

本文关键字:标题 参考 取代      更新时间:2023-09-26

当用户将鼠标放在图像映射的热点上时,下面的代码可以完美地显示图像。唯一的问题是什么?当点击"this。Href '当然会将用户带到热点图像本身。我想保留'href'来将用户发送到我选择的页面。

是否可以使用"title"而不是"href"来定义热点图像?如果有,请详细说明,我对javascript很陌生,谢谢!

<script type="text/javascript">
 function ShowPicC(sImage){document.housec.src = sImage}
 </script>
 <img border="0" src="main-image.png" width="640" height='640' usemap="#FPMap0">
 <map name="FPMap0">
 <area onmouseover='ShowPicC(this.href)' href='hotspot1.png' alt="thisalt" title="can-png-go-here.png" shape="circle"  coords="400,400,20">
 <area onmouseover="ShowPicC(this.href)" href="hotspot2.jpg" alt="youralt" title="can-png-go-here2.png" shape="circle" coords="420,420,20">
 <area onmouseover="ShowPicC(this.href)" href="hotspot3.jpg" alt="differentalt" title="can-png-go-here3.png" shape="circle" coords="440,440,20">
 <area onmouseover="ShowPicC(this.href)" href="hotspot4.jpg" alt="whateveralt" title="can-png-go-here4.png" shape="circle" coords="460,460,20">
 </map>
 <img name="housec" src="starter-hotspot-image.png" width="192" height="170">

当然可以,尽管title不是area的有效属性。你试过吗?

<area onmouseover="ShowPicC(this.title)" title="someotherimage.jpg" ...

你最好使用数据属性:

<area data-image="someotherimage.jpg" ...
https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Using_data_attributes