日期:2014-05-16  浏览次数:20475 次

超简单的定时器问题?
<Script>

function   show()   {
       
        document.write(new   Date().getSeconds());
          setTimeout( "hide() ",500);
}

function   hide()   {
         
        setTimeout( "show() ",500);
}

</Script>

<Body   onload= "show() ">
</Body>

怎么没用呢       郁闷~说网页中有错误`       --一新手  


------解决方案--------------------
document.write不能用在onload事件中及其以后.

------解决方案--------------------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN ">
<html>
<head>
<title> New Document </title>
<meta name= "Generator " content= "EditPlus ">
<meta name= "Author " content= " ">
<meta name= "Keywords " content= " ">
<meta name= "Description " content= " ">
</head>

<body>
<Script>
div = document.createElement( "div ");
div.id= "div ";
document.body.appendChild(div);

function show() {

// document.write(new Date().getSeconds());

div.innerHTML = new Date().getSeconds();
setTimeout( "hide() ",500);
}

function hide() {

setTimeout( "show() ",500);
}

</Script>

<Body onload= "show() ">
<input type= "button " onclick= "alert(document.body.innerHTML); ">
</Body>
</body>
</html>