我需要从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+'&color=ff6600&auto_play=false&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);
};
答案 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]+'&color=ff6600&auto_play=false&show_artwork=false'
}).appendTo(ele);
});
});