当前位置: 代码迷 >> ASP.NET >> 请教在网页中能不能动态显示时间啊
  详细解决方案

请教在网页中能不能动态显示时间啊

热度:4980   发布时间:2013-02-25 00:00:00.0
请问在网页中能不能动态显示时间啊,
请问在网页中能不能动态显示时间啊,就是网页的时间它会每秒自己更新,要用asp.net和c#实现的哦,谢谢了哦

------解决方案--------------------------------------------------------
<asp:Label ID= "theTime " runat= "server " Font-Bold= "True " Font-Size= "2cm " ForeColor= "Blue " Text= "Label "> </asp:Label>

protected void Page_Load(object sender, EventArgs e)
{
this.ClientScript.RegisterStartupScript(this.GetType(), "time interval ",
"setInterval( ' " + this.theTime.ClientID +
".innerText=new Date().toLocaleTimeString( ); ',1000); ", true);
}

其实只有一句话而已。从程序背后的设计可以看出程序员的一些习惯。例如,this.theTime.ClientID 而不是写死客户端 id,以及是否使用asp.net控件来简化程序。
  相关解决方案