有什么办法可以将所有这些结合起来以减少javascript的数量?结合jQuery/JavaScript函数
$(document).ready(function() {
$(".individualImagebox img").bind("click", function()
{
var src = $(this).attr("src");
if (src.search(/Red\.jpg$/) >= 0) return;
// Removes the red overlay from the images folder
$('.individualImagebox img').attr("src", function() {
var thisSRC = $(this).attr("src");
return thisSRC.replace(/Red\.jpg$/, ".jpg");
});
// Adds the red overlay from the images folder
$(this).attr("src", src.replace(/\.jpg$/, "Red.jpg") );
});
});
function ShowHide(index) {
var itemSelector = ".name:eq(" + index + ")";
$(".name .bio").fadeOut();
$(".name").not(itemSelector).fadeOut();
$(itemSelector).animate({"height": "show"}, { duration: 500 });
$(itemSelector + " .bio").animate({"height": "show"}, { duration: 500 });
}
“.jpg”是一个图像吗?如果没有,为什么不删除src属性? – bpierre 2011-03-29 15:12:22
.jpg是一个图像 – 2011-03-29 15:15:03
好吧,我更新了我的答案。 – bpierre 2011-03-29 15:23:33