<!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">
window.setTimeout("mouse();",1000)
function mouse()
{
var now = new Date();
var hours = now.getHours();
var mins = now.getMinutes();
var secd = now.getSeconds();
document.write(hours + ":" + mins + ":" + secd)
window.setTimeout("mouse();",1000)
}

</script>
<body>
</body>
</html>哪里错了呢  为何无法调用时间呢

解决方案 »

  1.   


    <!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">  
    function   mouse() 

    var   now   =   new   Date(); 
    var   hours   =   now.getHours(); 
    var   mins   =   now.getMinutes(); 
    var   secd   =   now.getSeconds(); 
    //设置body内容,如果用write输出会覆盖原有的HTML页面代码,所以第一次执行后JS代码就没有了,时间就停止
    //可以查看页面原代码看看
    document.body.innerHTML=hours   +   ":"   +   mins   +   ":"   +   secd;

    window.setInterval(mouse,1000);//设置每阁1秒钟调用一次mouse方法
    </script> 
    <body> 
    </body> 
    </html>