2010-11-27 3 views

답변

2

잘 구현하기 어렵지 않습니다.

아이디/클래스와 다른 속성을 tranferring 처리 doent 물론
(function($){ 
    $.fn.imageTag = function(options){ 
    var o = $.extend({}, $.fn.imageTag.options, options||{}); 

    this.each(function(){ 
     var selections = $.map(o.formats, function(e,i){ 
     return 'a[href$=.'+e+']'; 
     }).join(','); 

     $(selections, this).each(function(){ 
     var img = $('<img />').attr('src', $(this).attr('href')); 
     var tag; 
     if(o.wrapper){ 
      tag = $(o.wrapper).append(img); 
     } else { 
      tag = img; 
     } 

     if(o.css){ 
      tag.css(o.css); 
     } 

     $(this).replaceWith(tag); 
     }); 
    }); 

    return this; 
    }; 

    $.fn.imageTag.options = { 
    'formats': ['png','gif','jpg'], 
    'wrapper': null, // null or a tag like '<div></div>' 
    'css': null // null or a hash of css properties to be used as an arg for css() 
    }; 

})(jQuery); 

당신이 img 또는 옵션 포장 요소에 a에서 전송해야 할 수도 있습니다하십시오 버전에서 원시 (그리고 검증되지 않은) 형태의 ITD는 다음과 같이 수 .

+0

감사합니다. – Mark

+0

note 래퍼 옵션을 사용하려는 경우 꽤 큰 생략을 수정하여 다시 복사하고 붙여 넣을 수 있습니다. – prodigitalson

+1

다시 감사드립니다. 나는 또한 개인적으로 replaceWith (태그) 대신 html (태그)를 사용하고있다. – Mark