2013-05-13 30 views
-1

我碰到這個片段,其功能是用跨度包裹img標籤並製作跨度的圖像背景圖像。我的問題是,我如何才能使它只適用於特定的img標籤或某些div中的某些img標籤?如何使jquery片段僅適用於某些特定的標籤?

$(文件)。就緒(函數(){

$("img").load(function() { 
    $(this).wrap(function(){ 
     return '<span class="image-wrap ' + $(this).attr('class') + '" 
      style="position:relative; display:inline-block; background:url(' + $(this).attr('src') + ') no-repeat center center; width: ' + $(this).width() + 'px; height: ' + $(this).height() + 'px;" />'; 
    }); 
    $(this).css("opacity","0"); 
}); 

});

回答

0

簡單易用,只需用$("img")替換$("img")即可在不同的圖像集上運行「包裝」代碼,而不是在現場顯示所有圖像。例如,使用$(".extra img")來定位帶有「extra」(class =「extra」)類的標籤內部的任何img。

這是一個基本的,瑣碎的jQuery知識 - 我建議你閱讀jQuery教程或更好的,使用jQuery代碼學校http://try.jquery.com/學習如何使用jQuery。

相關問題