2017-03-12 6 views
0

저는 비교적 HTML에 익숙하지 않으므로 나와 함께하시기 바랍니다. 플리커에서 단추로 이미지를 가져 오는 이미 제공되는 간단한 자바 스크립트 기능을 추가하려고합니다. 버튼을 클릭해도 아무런 변화가 없습니다. 어디서 오류가 발생하는지 모르겠지만 제대로 실행되지 않는 함수와 관련이 있다고 생각합니다.버튼에 자바 스크립트 기능을 추가하려고합니다.

HTML :

<!DOCTYPE html> 
    <html> 
    <head> 
     <title>getJSON</title> 
     <meta charset="utf-8" /> 
     <script src="jquery-3.1.1.min.js"></script> 
    </head> 
    <body> 
    <button onclick="myFunction()">Click me</button> 
    <script> 
    function myFunction() 
    { //Functions don't need names. This function will simply run when the page loads 
     var flickerAPI = "http://api.flickr.com/services/feeds/photos_public.gne?jsoncallback=?"; 
     $.getJSON(flickerAPI, 
     { // The "$" simply refers to jQuery. This calls the getJSON function that is found inside jquery-3.1.1.min.js 
     tags: "Baruch College", //Some filter information in the format set by Flickr, who owns the JSON 
     tagmode: "any", 
     format: "json" 
     }) 
     .done(function(data) 
     { //Here, a an unnamed function is created made into the event handler for the "done" event... in other words, this is the code that will manifest itself when the getJSON is done. 
      $.each(data.items, function(i, item) 
      { 
      $("<img>").attr("src", item.media.m).appendTo("#images"); 
      if (i === 5) 
      { 
       return false; 
      } 
      }); 
     }); 
    } 
    </script> 

    </body> 
</html> 

나는 HTML에 언급 된 JQuery와 스크립트를 업로드 : http://pastebin.com/2CfRNkvq 당신은 그들이 검색 후 이미지가 배치 될 위치를 지정해야합니다

+0

로컬 서버에서 페이지를 실행해야합니다. –

+0

현재 실행중인 서버는 무엇입니까? – user1359783

답변

0

. 자바 스크립트 코드에서 각 이미지에 대해 <img> 태그를 만들고이를 id="images"과 함께 요소에 추가합니다.

다만이 같은 버튼 요소에 id="images"을 추가

<button onclick="myFunction()" id="images">Click me</button>

버튼을 클릭

는 이미지를 버튼 내부에 배치됩니다.

+0

고마워, 지금 일하고있어! – user1359783

관련 문제