繁体   English   中英

如何将链接添加到已具有过渡脚本的图像?

[英]How do I add a link to an image that already got a rollover script?

所以这是我当前的脚本,但是我似乎无法正确使用该链接,请当我单击悬停在其上的活动图像时,请帮助我并添加链接(至子页面)。 我需要在最后一个</a>之前插入新行吗?

<a href="URL ADDRESS">
    <img
        src="test.com/test1.png";
        onmouseover="this.src='test.com/test2.png'"; 
        onmouseout="this.src='test.com/test1'"; />
</a> 

我尝试了几种方法,但是我真的很陌生,无法弄清楚。

请尝试此操作,分号是不必要的并且放错了位置!

<a href="URL ADDRESS">
<img src="test.com/test1.png"
    onmouseover="this.src='test.com/test2.png'"
    onmouseout="this.src='test.com/test1'"/>
</a>

改用它。 您的分号仅与脚本处理程序相关。 您将它们放在属性之外,这些属性将是无效的HTML。 而src之后的那个是不正确的。

<a href="URL ADDRESS">
    <img
        src="test.com/test1.png"
        onmouseover="this.src='test.com/test2.png';" 
        onmouseout="this.src='test.com/test1';" />
</a>

试试这个。
附言
我用过JQuery

 $(document).ready(function(){ $('img').hover(function(){ $(this).attr('src','test.com/test2.png'); $(this).parent('a').attr('href','link when mouse enter the img'); },function(){ $(this).attr('src','test.com/test1'); $(this).parent('a').attr('href','link when mouse leave the img'); }); } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <a href="URL ADDRESS"> <img src="test.com/test1.png"; onmouseover="this.src='test.com/test2.png'"; onmouseout="this.src='test.com/test1'"; /> </a> 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM