gpt4 book ai didi

javascript - 尝试在div中的iframe中随机分配多个YouTube视频链接

转载 作者:行者123 更新时间:2023-12-03 06:19:40 24 4
gpt4 key购买 nike

尝试在页面上传时制作带有随机YouTube链接的iframe,而没有任何onclick

var glink = 0;
var games = new Array();

games[glink++] = "http://www.youtube.com/pRpvdcjkT3k";
games[glink++] = "http://www.youtube.com/Te4wx4jtiEA";

function randomglink() {
var random = rand(glink) - 1;
location.src = games[random];
}
<div><iframe width="283" height="242.5" src="randomglink()" frameborder="0" allowfullscreen></iframe></div>

最佳答案

这可以帮助您:

<html>
<head>
</head>
<body>
<div>
<iframe id="ifo" width="283" height="242.5" frameborder="0" allowfullscreen>
</iframe>
</div>

<script>
var glink = 1;
var games = new Array();

games[glink++] = "http://www.w3schools.com";
games[glink++] = "https://mail.google.com";

function randomglink() {
var randomNum =Math.floor((Math.random() * 2) + 1);
document.getElementById("ifo").src = games[randomNum];
}
randomglink();
</script>
</body>
</html>

关于javascript - 尝试在div中的iframe中随机分配多个YouTube视频链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37857888/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com