2013-06-02 1 views
0

이것은 Facebook에서 이미지를 가져 와서 표시하기위한 "내 코드"입니다.jquery를 편집하는 웹 사이트의 Facebook 이미지

<a href="image.source" class="highslide" onclick="return hs.expand(this)> 
<img src"image.source" width="167" height="167"> 
</a> 
:

는하지만 = "image.source"클래스 = "highslide"onclick을 = "(이)>

을 hs.expand 반환 < 주위에 저를 출력 도와주세요 A HREF를 이미지를 포장 할

원래 코드 :

<script type="text/javascript" src="underscore-min.js"></script> 
<script type="text/javascript"> 
$.getJSON('http://graph.facebook.com/261512740659107/photos').then(function (response) { 

    // 0-8, 0 returns the largest available images, 8 the smallest 
    var imageIndex = 4; 

    var images = _(response.data) 
     .chain() 
     .pluck('images') 
     .pluck(imageIndex) 
     .value(); 

    console.log(images); 

    _(images).each(function (image) { 
     $('#image-container').append(
     $('<img>').attr('src', image.source).attr('height', 167).attr('width', 167)); 
    }); 
}); 
</script> 

답변

0

당신은 당신의 <img> 태그 주위 <a> 태그를 넣어() 함수를 감싸는 jQuery를 사용할 수 있습니다,745.대신 appendTo()를 사용하여 새 요소의 인스턴스를 가져 와서 wrap() 할 수 있습니다.

$.getJSON('http://graph.facebook.com/261512740659107/photos').then(function (response) { 

    // 0-8, 0 returns the largest available images, 8 the smallest 
    var imageIndex = 4; 

    var images = _(response.data) 
     .chain() 
     .pluck('images') 
     .pluck(imageIndex) 
     .value(); 

    _(images).each(function (image) { 
     $($('<img>').attr({'src': image.source, 'height': 167, 'width': 167})).appendTo('#image-container').wrap('<a href="' + image.source + '" class="highslide" onclick="return hs.expand(this);" />'); 
    }); 
}); 
+0

고맙습니다. 이제 작동 중입니다. –

관련 문제