我无法让鼠标进入鼠标离开功能正常工作。我知道我可以使用 .hover 选项,我想让 mouseenter/mouseleave 正常工作,然后再进行操作。
我看到的是,我打开了 chrome,正在检查 img,它说 src 文件正在更改,但我没有看到明显的变化。有人可以帮忙吗
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script src="jquery-1.4.3.min.js" type="text/javascript"></script>
</head>
<body>
<img id="menuHome" src="m_home.gif" />
<script type="text/javascript">
$(document).ready(function() {
$("#menuHome").mouseenter(function() {
$(this).attr({ src: 'm_home_roll.gif' });
});
$("#menuHome").mouseleave(function() {
$(this).attr({ src: 'm_home.gif' });
});
});
</script>
</body>
</html>
最佳答案
我认为 Chrome 也有类似的问题,我似乎记得使用 mouseover
和 mouseout
来代替。所以像这样:
$(document.ready(function() {
$('#menuHome')
.mouseover(function() {
$(this).attr({src: 'm_home_roll.gif'});
})
.mouseout(function() {
$(this).attr({src: 'm_home.gif'});
});
});
也无需选择该元素两次(因此只有一个 $('#menuHome')
行)。
关于.net - jquery mouseenter 鼠标离开,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4158957/