每秒在页面中显示时间 [英] Show time in page every second

查看:102
本文介绍了每秒在页面中显示时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨 我的页面有时间.我写在codebehind的page_load中.因此显示为静态.
直到每秒重复一次,我该怎么办?
非常感谢

Hi I have time in my page. I write it In page_load of codebehind . therefore it be shown static .
What shoul I do until it be repeat every second?
Thanks very much

推荐答案

为什么不使用JavaScript,Javascript可以使您每秒显示当前时间
Why Don''t you use javascript, Javascript enable you to display currenttime in every second
<script type="text/javascript">
    function ShowTime() {
        var dt = new Date();
        document.getElementById("<%= TextBox1.ClientID %>").value = dt.toLocaleTimeString();
        window.setTimeout("ShowTime()", 1000);
    }
</script>

<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>

<script type="text/javascript">
    // a startup script to put everything in motion
    window.setTimeout("ShowTime()", 1000);
</script>



有关其他参考,请尝试在ASP.NET中使用AJAX计算页面停留时间 [^ ]



For other References Try Counting Time on Page with AJAX in ASP.NET[^]


您不应该在页面加载中编写时间逻辑.
实际上,AS.Net是服务器端框架,因此您应该使用JavaScript来做到这一点.
开始于 [
You should not be writing your time logic in page load.
Infact, AS.Net is a server side framework so you should be using JavaScript to do this.
Start with this[^].


您应该使用javascript进行操作,但是当您通过javascript花费时间或日期时,它是用户特定的.
用户的机器日期时间可能是错误的,您不应依赖它.

您应该通过pageLoad上的服务器脚本
You should do it in javascript, however when you take time or date through javascript, it is user specific.
user''s machine date time may be wrong and you should not rely on that.

you should take current time through server script
System.DateTime.Now()

花费当前时间,并在javascript中编写一个函数以使其每秒递增.

希望你有逻辑.

on pageLoad, and write a function in javascript to increment it every second.

Hope you got the logic.


这篇关于每秒在页面中显示时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆