Php 使用jquery函数鼠标悬停时图像不会更改
jQuery代码:Php 使用jquery函数鼠标悬停时图像不会更改,php,jquery,html,Php,Jquery,Html,jQuery代码: <a href="#"> <div class="col-md-5 campaigns" id="hoverimg"> <img class="featurette-image img-responsive" src="images/tee1.png" > <li class="progressbar"> <p> &l
<a href="#">
<div class="col-md-5 campaigns" id="hoverimg">
<img class="featurette-image img-responsive" src="images/tee1.png" >
<li class="progressbar">
<p>
<!--<strong>Orders Completed</strong>--> <span class="pull-right small muted">78%</span>
</p>
<div class="progress tight">
<div class="bar" style="width: 78%;">
</div>
</div>
</li>
<div class="prodheading">
<h2>Heading 1</h2>
</div>
</div>
</a>
我不明白这背后的真正问题。您的JavaScript在每一行前面都有//,因此被完全注释掉了。如果您希望发生任何事情,必须删除这些 有一些问题: .replace是一个JavaScript字符串方法,需要两个参数: 正则表达式及其应用 替换字符串。 .match/[^\.]+/+images/tee2.png可能无法像您预期的那样工作:.match/[^\.]+/将返回应用它的字符串中不包含点“.”的第一部分。这真的是你想做的吗 例如:
<script>
$('document').ready(function ()
{
$(function ()
{
$("#hoverimg")
.mouseover(function ()
{
var src = $(this).attr("src").match(/[^\.]+/) + "images/tee2.png";
$(this).attr("src", src);
})
.mouseout(function ()
{
var src = $(this).attr("src").replace("images/tee2.png");
$(this).attr("src", src);
});
});
});
</script>
会回来的
"path/subpath/filename.ext".match(/[^\.]+/) + "images/tee2.png"
您已经将id应用于div标记,并且在jquery中尝试获取src。您必须将id分配给img标签。为什么您注释掉了所有代码?您想用它做什么。match/[^\.]+/?在您的注释之前,我刚刚更正了它谢谢您的支持这是您解决问题的方式,是对其中一个答案的答复还是对您的问题的补充?请在你的帖子中添加一些解释。仅仅是代码转储很少有用。
"path/subpath/filenameimages/tee2.png"
$("#hoverimg1").hover(
function() {$(this).attr("src","images/teee2.png");},
function() {$(this).attr("src","images/teee1.png");
});