javascript - 如何更改 img src 链接鼠标悬停?

标签 javascript html css hover

HTML

<div module="product_listnormal">
        <ul>
            <li>
                <input type="checkbox" class="{$product_compare_class} {$product_compare_display|display}">
                <div id="prdImgWrapper">
                     <a href="/product/detail.html{$param}" class="prdImg"><img src="{$image_medium}" alt="" class="prdImgImg"/></a>
                </div>
.....

所以我在img标签中添加了onmouseover

<a href="/product/detail.html{$param}" class="prdImg"><img src="{$image_medium}" onmouseover="this.src={$image_medium} + 'aaa'" alt="" class="prdImgImg"/></a>

但它不调用 {$image_medium}aaa 链接 怎么了?

ex) 如果 $image_medium = 111.png $image_medium + aaa = 111aaa.png

最佳答案

我像这样在鼠标悬停和鼠标离开时使用

onmouseover='this.src = this.src.replace(".jpg","_2.jpg")' onmouseleave='this.src = this.src.replate("_2.jpg", ".jpg")'

此源可以使用所有图片

关于javascript - 如何更改 img src 链接鼠标悬停?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27011139/

相关文章:

html - 如何制作一个布局,其中 3 个元素在 HTML 页面的高度/宽度上居中

html - 在 IE7 中链接不可点击

javascript - 如何在动态创建的 <an></a> 标签上添加事件监听器 click()

javascript - 我如何根据用户提供的过滤值显示搜索结果?

javascript - 从 Node.js 运行脚本,捕获标准输出,通过 Web 套接字发送

javascript - 悬停时的jquery toggleClass child

html - 导航栏中导航栏元素的垂直对齐问题

javascript - 奇怪的输出结果

html - 根据复选框更改文本区域的样式

html - MVC3- Razor : How to use mailto dynamically