我先写了代码,没有使用函数来原型化,当然,它工作得很好:
$(function() {
$(".PortfolioFade img")
.mouseover(function() {
popup('PORTFOLIO');
var src = $(this).attr("src").replace("images/paperclip.png", "images/paperclip-black.png");
/*var src = $(this).attr("src").match(/[^\.]+/) + "-black.png";*/
$(this).attr("src", src);
})
.mouseout(function() {
;
/*var src = $(this).attr("src").replace("images/paperclip-black.png", "images/paperclip.png");
$(this).attr("src", src); Look at popup.js mouseover events*/
});
});
但是,当我以函数形式表达相同的内容时,函数调用似乎不起作用。
$(document).ready(function() {
// put all your jQuery goodness in here.
$('body').hide().fadeIn(1000);
function ImageRollover(image_element, popup_name, original, replacement)
{
$(element)
.mouseover(function(){
popup(popup_name);
var src = $(this).attr("src").replace(original,replacement);
$(this).attr("src",src);
})
.mouseout(function(){
;
});
}
ImageRollover(".Portfolio img",'PORTFOLIO',"images/paperclip.png","images/paperclip-black.png");
});
在别处定义函数似乎也没有任何效果。