加载除密钥之外具有相同src的多个iFrame

时间:2013-11-21 17:46:50

标签: javascript jquery arrays iframe for-loop

我需要从Soundcloud加载大约十几个iFrame,除了曲目ID之外,链接都是相同的。我想知道是否可以将元素与密钥和密钥的其余部分连接起来?像这样: 我有一个数组中的键,我试图迭代它们。也许我的代码会更好地解释。

    $(document).ready(function () {
  var iframe = [$('<iframe width="275" height="60" scrolling="no" frameborder="no" src="https://w.soundcloud.com/player/?url=https%3A//api.soundcloud.com/tracks/'+key+'&amp;color=ff6600&amp;auto_play=false&amp;show_artwork=false"></frame>')];
  var key = [ 105222048,
              115799341,
              115799196,
              115728933,
              115798967,
              111209945,
              115798780,
              115798571,
              115798398,
              115798240,
              115798083,
              115797941,
              115797749
            ];
});
for (var j = 0,  i = $('.wrapper').length; j > i; j++) {
  console.log(iframe+key);
};

1 个答案:

答案 0 :(得分:1)

类似的东西:

$(function() {
    var keys = [ 105222048,
                 115799341,
                 115799196,
                 115728933,
                 115798967,
                 111209945,
                 115798780,
                 115798571,
                 115798398,
                 115798240,
                 115798083,
                 115797941,
                 115797749
    ];

    $('.wrapper').each(function(i, ele) {
        $('<iframe />', {
            width       : 275,
            height      : 60,
            scrolling   : 'no',
            frameborder : 'no',
            src         : 'https://w.soundcloud.com/player/?url=https%3A//api.soundcloud.com/tracks/'+key[i]+'&amp;color=ff6600&amp;auto_play=false&amp;show_artwork=false'
        }).appendTo(ele);
    });
});