有什麼辦法可以將所有這些結合起來以減少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