0

我想在网站上有一个秒表,它在标签上显示运行时间而不重新加载页面。是否可以在客户端执行此操作?我应该使用 Ajax 计时器还是 .net 中的其他东西?

网站是用 C# 编写的。

一些链接或演示会非常有帮助!谢谢 !

4

2 回答 2

2

您可以使用setTimeout使用基本 JavaScript 执行此操作:

var totalSeconds = 0

function stopwatch() {
    // increment the seconds
    totalSeconds++;

    // display the seconds to the user
    document.getElementById("<%=myLabel.ClientID%>").innerHTML = "You have spent " + totalSeconds + " on this page.";

    // wait a second and call the timer again
    setTimeout("stopwatch()", 1000);
}

// trigger the timer
timer();

更新:如果用户要在页面上停留一段时间,您可能希望显示一条对用户更友好的消息,然后是“您在此页面上花费了 1000 秒”。这是一个快速的 JavaScript函数,可以将秒数转换为经过的时间。

于 2010-02-25T19:31:21.667 回答
1

只能在 javascript 中进行。那里有很多例子。只是谷歌他们。这是一个

于 2010-02-25T19:34:00.197 回答