<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<script language="javascript" type="text/javascript">
function refresh(){
location.reload();
} function change(){
var i = Math.round(Math.random()*1+1);
document.write("<img src = '"+i+".jpg'>");
setTimeout("refresh()",3000);
}
</script><body onload="change()"></body>
</html>缺少对象!
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<script language="javascript" type="text/javascript">
function refresh(){
location.reload();
} function change(){
var i = Math.round(Math.random()*1+1);
document.write("<img src = '"+i+".jpg'>");
setTimeout("refresh()",3000);
}
</script><body onload="change()"></body>
</html>缺少对象!
可以用setInterval试试
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<script language="javascript" type="text/javascript">
function refresh(){
location.reload();
} function change(){
var i = Math.round(Math.random()*5+1);
var img=document.createElement("img");
img.src=i+".jpg";
document.body.appendChild(img);
//document.write("<img src = '"+i+".jpg'>");
setTimeout("refresh()",3000);
}
</script><body onload="change()"></body>
</html>
原因已经说出来了 是不是refresh函数被覆盖了 settime调用的时候就没了
应该是如1楼和5楼说的,refresh函数在document.write的时候被覆盖了,settime调用的时候就没了
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<script language="javascript" type="text/javascript">
function refresh(){
location.reload();
} function change(){
var i = Math.round(Math.random()*1+1);
document.getElementById("pic").src = i+".jpg";
document.getElementById("pic").title = i+".jpg";
setTimeout("refresh()",3000);
}
</script><body onload="change()">
<img src="" id="pic" title="">
</body>
</html>
实践了,实践大于理论!
测试代码如下:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<script language="javascript" type="text/javascript">
function refresh(str){
alert(str)
}
function change(){
setTimeout("refresh(123)",1000);//可行,弹出123
setTimeout(refresh,3000);//可行,因无参数弹出undefined
setTimeout("refresh",5000);//压根没反应……
}
</script><body onload="change()"></body>
</html>结论是6楼的代码确实不可行