-2
<body>

  <input type="text" id="search" onchange="doSearch()" />

  <div id="catalog">
  </div>

  <div id="each_track">
  </div>

  <script>
  SC.initialize({
    client_id: '*****************'
  });

  function doSearch() {
    var searchTerm = document.getElementById('search').value;

        // Search soundcloud for artists
        SC.get('/tracks', { q: searchTerm, license: 'cc-by-sa' }, function(tracks) {
          for(track in tracks) {
            var img = document.createElement('img');
            var catalog = document.getElementById('catalog');
            img.setAttribute("src",tracks[track]["artwork_url"]);
            catalog.appendChild(img);
            }
         }
        });
      };
      </script>
    </body>

コメントに応じて、すべての画像を div に追加するのではなく、各 img に div を追加するだけです。

4

2 に答える 2

2

試す

function doSearch() {
    var searchTerm = document.getElementById('search').value;

    // Search soundcloud for artists
    SC.get('/tracks', { q: searchTerm, license: 'cc-by-sa' }, function(tracks) {
        for(track in tracks) {
            var img = document.createElement('img');
            var catalog = document.getElementById('catalog');
            img.setAttribute("src",tracks[track]["artwork_url"]);

            var div = document.createElement('div');
            div..appendChild(img);

            catalog.appendChild(div);
        }
    });
};
于 2013-04-25T00:28:17.213 に答える