代码如下<html>
<head>
<meta http-equiv="contentType" content="text/html;charset=utf-8">
<script src="./jquery.js"></script>
<script>
function f1()
{
setsrc(" http://www.baidu.com");
setTimeout(f2(),2000);
}
function f2()
{
setsrc(" http://www.google.com");
setTimeout(f3(),2000);
}
function f3()
{
setsrc(" http://www.163.com");
}
function setsrc(sr)
{
$("#theone").attr("src",sr);
}
</script>
</head>
<body>
<iframe id="theone" src="" width="600" height="200"></iframe>
<input type="button" onclick="f1()"/>
</body>
</html>
这样为什么不行
我就想让每2秒 切换一次页面
<head>
<meta http-equiv="contentType" content="text/html;charset=utf-8">
<script src="./jquery.js"></script>
<script>
function f1()
{
setsrc(" http://www.baidu.com");
setTimeout(f2(),2000);
}
function f2()
{
setsrc(" http://www.google.com");
setTimeout(f3(),2000);
}
function f3()
{
setsrc(" http://www.163.com");
}
function setsrc(sr)
{
$("#theone").attr("src",sr);
}
</script>
</head>
<body>
<iframe id="theone" src="" width="600" height="200"></iframe>
<input type="button" onclick="f1()"/>
</body>
</html>
这样为什么不行
我就想让每2秒 切换一次页面
<head>
<meta http-equiv="contentType" content="text/html;charset=utf-8">
<script src="jquery-1.4.2.min.js"></script>
<script>
function f1()
{
var i = 0;
var urls = ['http://www.baidu.com','http://www.google.com','http://www.163.com'];setInterval(function() {
if(i==urls.length)
clearInterval();
setsrc(urls[i])
i++;
},2000);}
function setsrc(sr)
{
$("#theone").attr("src",sr);
}
</script>
</head>
<body>
<iframe id="theone" src="" width="600" height="200"></iframe>
<input type="button" onclick="f1()"/>
</body>
</html>
把3个函数里的红色的括号去掉,或者改为
setTimeout("f2()",2000);