<html><head>
<script type="text/javascript">
function show()
{
var time=new Date();
var hour=time.getHours();
var minute=time.getMinutes();
var second=time.getSeconds();
document.write(hour+":"+minute+":"+second);
setTimeout("show()",1000);
}
</script>
</head><body>
<input type="button" value="点击开始时间" onClick="show()"/></body></html>我想让他一直动态显示时间 为什么不可以?

解决方案 »

  1.   

    <html><head>
    <script type="text/javascript">
    function show()
    {
    var time=new Date();
    var hour=time.getHours();
    var minute=time.getMinutes();
    var second=time.getSeconds();
    document.getElementById("x").innerHTML=(hour+":"+minute+":"+second);
    setTimeout("show()",1000);
    }
    </script>
    </head><body>
    <input type="button" value="点击开始时间" onClick="show()"/>
    <div id=x></div>
    </body></html>
      

  2.   

    为什么 只会执行一次
    setTimeout 不是在嘛??
      

  3.   

    Do not use the write method or the writeln method on the current document after the document has finished loading unless you first call the open method, which clears the current document window and erases all variables.
      

  4.   

    document.write会把当前页面的所有变量清除