我是jQuery的新手,所以如果您能提供任何帮助/建议,我将不胜感激!
我让这个在jsFiddle中工作:http://jsfiddle.net/cakeeater/LUAtb/10/
基本上,当您将鼠标悬停在图像上时,我只需要图像的标题来替换"Hello“文本。
jQuery().ready(function() {
jQuery("#caption").text('Hello'); });
jQuery('img.gallery').mouseenter(function() {
var title = $(this).attr("title");
jQuery("#caption").text(title); });
jQuery('img.gallery').mouseleave(function() {
jQuery("#caption").text('Hello'); });
然而,当我将它放入网站时,"Hello“文本是唯一有效的功能-并且图像标题不会显示在悬停状态:http://bit.ly/MNgdUS
我相信可能有一种更好的方式来写脚本...我在Firebug中看不到任何错误,我也尝试禁用站点上的所有其他脚本,结果相同。有什么想法吗?
发布于 2012-08-23 05:07:50
这应该是可行的:
$(function() {
"use strict";
$("#gallerydescription").text("Hello");
$("img.team").hover(
function() {
$("#gallerydescription").text($(this).attr("alt"));
},
function() {
$("#gallerydescription").text("Goodbye");
}
);
});
使用.hover()
。
.hover()方法绑定mouseenter和mouseleave事件的处理程序。您可以使用它来简单地将鼠标在元素中的时间内的行为应用于元素。
调用$(selector).hover(handlerIn, handlerOut)
是以下的简写:
$(selector).mouseenter(handlerIn).mouseleave(handlerOut);
https://stackoverflow.com/questions/12081019
复制相似问题