我想在网站上有一个秒表,它在标签上显示运行时间而不重新加载页面。是否可以在客户端执行此操作?我应该使用Ajax计时器还是来自.net的其他人?
网站使用C#。
某些链接或演示会非常有用!谢谢!
答案 0 :(得分:2)
您可以使用基本JavaScript使用setTimeout:
执行此操作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秒”。 Here's a quick JavaScript函数将'秒转换为经过的时间。
答案 1 :(得分:1)
只能在javascript中进行。那里有很多例子。只需google them。这是one。