这个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;">
用户名:<asp:Label ID="Operator" runat="server"
Text="Label"></asp:Label></td>
<td align="right" style="width: 650px; height: 18px;">
<div id=time></div>
</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>
<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;">
用户名:<asp:Label ID="Operator" runat="server"
Text="Label"></asp:Label></td>
<td align="right" style="width: 650px; height: 18px;">
<div id=time></div>
</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>
document.getElementById("time").innerHTML=year+"年"+month+"月"+date+"日"+" "+hours+":"+minutes+":"+seconds;
//...
改为document.getElementByid("time").innerHTML=year+"年"+month+" 月"+date+"日"+" "+hours+":"+minutes+":"+seconds;
<div id=time></div>
改为<div id="time"></div>
<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放到放到页面后面
{
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>
div不能放在td里,怎么能获得时间值呢
只要js在后面(相对于<div id=time></div>)直接time.innerHTML或者document.getElementById("time").innerHTML都可以获取到,楼主的程序就是顺序的问题
<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;">
用户名:<asp:Label ID="Operator" runat="server"
Text="Label"></asp:Label></td>
<td align="right" style="width: 650px; height: 18px;">
<div id="time"></div>
</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>
还真是顺序问题,放在后面就可以了,但是一编译就报TD中不能有DIV,我怎么替换呢,你写的那个我应该放在那里呢
除了用DIV id=time 这样获得time的值还有什么办法吗?
除了用DIV id=time 这样获得time的值还有什么办法吗?
<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>
这个添加id <td align="right" style="width: 650px; height: 18px;" id="time">