尝试在页面上传时制作带有随机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>