如何将js文件中的文本添加到iframe中的src 并且不会是另一个iframe中的相同文本
var games = new Array ();
games[0] = "mhgxcdufRbE?rel=0&showinfo=0";
games[1] = "jrndhugilod?rel=0&showinfo=0";
games[2] = "oloprokbanse?rel=0&showinfo=0";
games[3] = "nfbeuujshre?rel=0&showinfo=0";
games[4] = "sd54ddsaegdd?rel=0&showinfo=0";
games[5] = "h5gffy73jssa?rel=0&showinfo=0";
games[6] = "ffa87gb3n21s?rel=0&showinfo=0";
var i = Math.floor(7*Math.random())
document.write(games[i]);

<iframe src="https://www.youtube.com/embed/ + games[i]" width="283" height="242.5" frameborder="0" allowfullscreen></iframe>
&#13;
答案 0 :(得分:0)
var games = [];
games[0] = "mhgxcdufRbE?rel=0&showinfo=0";
games[1] = "jrndhugilod?rel=0&showinfo=0";
games[2] = "oloprokbanse?rel=0&showinfo=0";
games[3] = "nfbeuujshre?rel=0&showinfo=0";
games[4] = "sd54ddsaegdd?rel=0&showinfo=0";
games[5] = "h5gffy73jssa?rel=0&showinfo=0";
games[6] = "ffa87gb3n21s?rel=0&showinfo=0";
var i = Math.floor( 7 * Math.random() ),
iFrame = document.getElementById('iFrame').src = 'https://www.youtube.com/embed/' + games[i];
&#13;
<iframe id="iFrame" src="<INSERT DEFAULT URL HERE?>" width="283" height="242.5" frameborder="0"></iframe>
&#13;
另外fiddle
仅使用随机网址设置<iframe>
src 。