首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

超简单的定时器有关问题

2012-02-08 
超简单的定时器问题?Scriptfunctionshow(){document.write(newDate().getSeconds())setTimeout( hide(

超简单的定时器问题?
<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>

热点排行