我需要将图像URL从JSON列表到JavaScript幻灯片放映功能。
有人可以告诉我如何用JSON对象中的URL替换函数中的URL列表吗?
<script type="text/javascript">
$(document).ready(function() {
$("body").backgroundCycle({
imageUrls: [
'res/img/bg1.jpg',
'res/img/bg2.jpg',
'res/img/bg3.jpg'
],
fadeSpeed: 2000,
duration: 5000,
backgroundSize: SCALING_MODE_COVER
});
});
</script>
这是JSON:
{
"topbanners": [
"http:\/\/kuuza.co.tz\/serengeti_090.jpg",
"http:\/\/kuuza.co.tz\/p4030235.jpg",
"http:\/\/kuuza.co.tz\/banner1.jpg"
]
}
答案 0 :(得分:0)
function getUrls() {
var obj = {
"topbanners": [
"http:\/\/kuuza.co.tz\/serengeti_090.jpg",
"http:\/\/kuuza.co.tz\/p4030235.jpg",
"http:\/\/kuuza.co.tz\/banner1.jpg"
]
};
var banners = obj.topbanners;
var urls = [];
for (var i = 0; i < banners.length; i++) {
urls.push(banners[i]);
}
return urls;
}
$(document).ready(function () {
$("body").backgroundCycle({
imageUrls: getUrls(),
fadeSpeed: 2000,
duration: 5000,
backgroundSize: SCALING_MODE_COVER
});
});