这个JS函数怎么显示日期呢?在页面里什么都没有了还报错,说没有声明time<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Top.aspx.cs" Inherits="admin_Top" %><!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 runat="server">
    <title>无标题页</title>
    <script type="text/javascript">
function show() 

now=new Date(); 
year=now.getYear(); 
month=now.getMonth()+1; 
date=now.getDate(); 
hours=now.getHours(); 
minutes=now.getMinutes(); 
seconds=now.getSeconds(); 
if(minutes<=9) 
minutes="0"+minutes 
if(seconds<=9) 
seconds="0"+seconds
time.innerHTML=year+"年"+month+"月"+date+"日"+" "+hours+":"+minutes+":"+seconds;setTimeout("show()",1000); 
}
show();
</script> 
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <h1>标题</h1>
        <TR>
<TD COLSPAN=2 style="background-color: #99cc33; font-size: 12px; color: white; height: 32px;">
            <table cellspacing="0">
                <tr>
                    <td style="width: 806px; height: 18px;">
                        &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 用户名:<asp:Label ID="Operator" runat="server"
                Text="Label"></asp:Label></td>
                    <td align="right" style="width: 650px; height: 18px;">
                       <div id=time></div>                        &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
                    </td>
                    <td>
                        <a href="Login.aspx"><img width="78" height="20" alt="退出系统" src="../image/login/logout.gif" /></a>
                    </td>
                </tr>
            </table>
        </TD>
</TR>
    </div>
    </form>
</body>
</html>

解决方案 »

  1.   

    id为time标签在下面呢,页面加载顺续是从上向下的,将js放到下面就好了
      

  2.   

    修改一个地方...//...
    document.getElementById("time").innerHTML=year+"年"+month+"月"+date+"日"+" "+hours+":"+minutes+":"+seconds;
    //...
      

  3.   

    document.getElementByid("time").innerHTML=year+"年"+month+"月"+date+"日"+" "+hours+":"+minutes+":"+seconds;
      

  4.   

    time.innerHTML=year+"年"+month+" 月"+date+"日"+" "+hours+":"+minutes+":"+seconds;
    改为document.getElementByid("time").innerHTML=year+"年"+month+" 月"+date+"日"+" "+hours+":"+minutes+":"+seconds;
    <div id=time></div> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    改为<div id="time"></div> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
      

  5.   

    最后是在页面加载时再调用,如
      <script type="text/javascript">
    function show()
    {
    now=new Date();
    year=now.getYear();
    month=now.getMonth()+1;
    date=now.getDate();
    hours=now.getHours();
    minutes=now.getMinutes();
    seconds=now.getSeconds();
    if(minutes<=9)
    minutes="0"+minutes
    if(seconds<=9)
    seconds="0"+seconds
    document.getElementById("time").innerHTML=year+"年"+month+"月"+date+"日"+" "+hours+":"+minutes+":"+seconds;setTimeout("show()",1000);
    }widow.onload=function(){
    show();
    }

    </script>或者如1L说的把JS放到放到页面后面
      

  6.   

    <script type="text/javascript">//放到<div id=time></div>后面的任何地方皆可function show() 

    now=new Date(); 
    year=now.getYear(); 
    month=now.getMonth()+1; 
    date=now.getDate(); 
    hours=now.getHours(); 
    minutes=now.getMinutes(); 
    seconds=now.getSeconds(); 
    if(minutes<=9) 
    minutes="0"+minutes 
    if(seconds<=9) 
    seconds="0"+seconds
    time.innerHTML=year+"年"+month+"月"+date+"日"+" "+hours+":"+minutes+":"+seconds;setTimeout("show()",1000); 
    }
    show();
    </script>
      

  7.   


    div不能放在td里,怎么能获得时间值呢
      

  8.   

    div不能放在td里,怎么能获得时间值呢
      

  9.   


    只要js在后面(相对于<div id=time></div>)直接time.innerHTML或者document.getElementById("time").innerHTML都可以获取到,楼主的程序就是顺序的问题
      

  10.   

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Top.aspx.cs" Inherits="admin_Top" %><!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 runat="server">
      <title>无标题页</title>
      <script type="text/javascript">
    function show()
    {
    now=new Date();
    year=now.getYear();
    month=now.getMonth()+1;
    date=now.getDate();
    hours=now.getHours();
    minutes=now.getMinutes();
    seconds=now.getSeconds();
    if(minutes<=9)
    minutes="0"+minutes
    if(seconds<=9)
    seconds="0"+seconds
    document.getElementById("time").innerHTML=year+" 年"+month+"月"+date+"日"+" "+hours+":"+minutes+":"+seconds;setTimeout("show()",1000);
    }
    onload=show;</script> </head>
    <body>
      <form id="form1" runat="server">
      <div>
      <h1>标题</h1>
      <TR>
    <TD COLSPAN=2 style="background-color: #99cc33; font-size: 12px; color: white; height: 32px;">
      <table cellspacing="0">
      <tr>
      <td style="width: 806px; height: 18px;">
      &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 用户名:<asp:Label ID="Operator" runat="server"
      Text="Label"></asp:Label></td>
      <td align="right" style="width: 650px; height: 18px;">
      <div id="time"></div> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
      </td>
      <td>
      <a href="Login.aspx"><img width="78" height="20" alt="退出系统" src="../image/login/logout.gif" /></a>
      </td>
      </tr>
      </table>
      </TD>
    </TR>
      </div>
      </form>
    </body>
    </html>
      

  11.   


    还真是顺序问题,放在后面就可以了,但是一编译就报TD中不能有DIV,我怎么替换呢,你写的那个我应该放在那里呢
      

  12.   


    除了用DIV id=time  这样获得time的值还有什么办法吗?
      

  13.   


    除了用DIV id=time 这样获得time的值还有什么办法吗?
      

  14.   

    <!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=gb2312" />
    <title>在线时钟</title>
    <script language="javascript"> 
    function showTime()
    {
    //获取系统当前时间
    var now= new Date();
    //获取小时
    var hour=now.getHours();
    //获取分钟部分
    var minute=now.getMinutes();
    //获取秒部分
    var second=now.getSeconds();
    var time=document.getElementById("time");
    if(hour<10)
    {
    hour="0"+hour;
    }
    if(minute<10)
    {
    minute="0"+minute;
    }
    if(second<10)
    {
    second="0"+second;
    }
    time.innerHTML="现在时间是:<font color='red'><b>"+hour+":"+minute+":"+second+"</b></font>";
    setTimeout("showTime()",1000)
    }
    </script>
    </head>
    <body onload="showTime()">
    <div id="time"></div>
    </body>
    </html>
      

  15.   

    一编译就报TD中不能有DIV这个应该可以啊,我经常这么做
      

  16.   

    把<div id="time"></div>删除
    这个添加id <td align="right" style="width: 650px; height: 18px;" id="time">
      

  17.   

    TD中不能有DIV  这个只是你的嵌套规则的问题 其实div放在td里一点问题都没有。   推荐把JS放在后面   用document.getElementById('time')来获取DOM元素  就可以了 上面都已经说过。