我有以下代码将YouTube视频显示为我网站的背景
<iframe frameBorder="0" height="100%" width="100%"
src="https://youtube.com/embed/ID?autoplay=1&controls=0&showinfo=0&autohide=1">
如何从ID的数组中选择ID,我是新手,但我想我需要使用带有数组的javascript脚本来选择随机ID?
由于
解决了我使用此https://gist.github.com/alishutc/a6b1b0fc11a28a627897
答案 0 :(得分:0)
尝试使用javascript
var id = ['WfmeUdQb4ek', 'CJdOiXwCyzY', '6pilrScSXms', 'TiFthD8t_DI'];
//console.log(id);
setTimeout("changeVideo()", 5000);
var x = 0;
function changeVideo() {
console.log(id[x]);
//console.log("https://youtube.com/embed/"+id[x]+"?autoplay=1&controls=0&showinfo=0&autohide=1");
document.getElementById("video").src = "https://youtube.com/embed/" + id[x] + "?autoplay=1&controls=0&showinfo=0&autohide=1";
x++;
}
&#13;
<!--<iframe frameBorder="0" height="100%" width="100%"
src="" id="video"></iframe>-->
<iframe width="560" height="315" src="" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen id="video"></iframe>
&#13;