我想知道是否有可能拥有一个带有 iframe 和一些每 30 秒更改 iframe 内容的 jquery 代码的站点。内容在不同的网页中。
像这样:
<html>
<head>
<script type="text/javascript" src="jquery.js"></script>
<script>
$(document).ready(function(){
var array = new array();
array[0] = 'http://webPage1.com';
array[1] = 'http://webPage2.com';
// And so on.
// Do something here to change the iframe every 30 second
});
</script>
</head>
<body>
<iframe id="frame"></iframe>
</body>
</html>
最佳答案
<html>
<head>
<script type="text/javascript" src="jquery.js"></script>
<script>
$(document).ready(function(){
var locations = ["http://webPage1.com", "http://webPage2.com"];
var len = locations.length;
var iframe = $('#frame');
var i = 0;
setInterval(function () {
iframe.attr('src', locations[++i % len]);
}, 30000);
});
</script>
</head>
<body>
<iframe id="frame"></iframe>
</body>
</html>
关于jquery - 如何使用 jquery 动态更改 iframe 中的内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1554396/