如何使用jquery来计算页面上的操作之间需要多长时间(按钮单击之间的秒表)
我的目标是计算用户浏览一堆页面(单个页面上的隐藏 div)所需的时间,以便我可以记录最好以 mm:ss 或仅 sss 为单位的时间。
我将从一个输入按钮开始,该按钮应该启动计时器,然后单击其中一个隐藏 div 上的另一个按钮,它将停止计时器。
最终目标是在同一页面上有 3 个计时器,并且必须通过 jquery 或 w/e 否则可以用于在单击的 2 个不同按钮之间进行计时。
我知道如何在控制器中完成它,但因为我需要收集 3 次单独的时间,并且不能通过 3 次单独的操作/数据库保存来完成它。
到目前为止,我发现的只是您已经设置了时间,然后它充当倒计时而不是秒表。
任何帮助将不胜感激。
My aim is to time how long it take a user to navigate through a bunch of pages(hidden divs on single page) so I can record time taken preferably in mm:ss or just sss.
I would start from a input button which should start the timer and then upon click of another button on 1 of the hidden divs it will stop the timer.
End goal would be to have 3 timers on the same page and it has to be via jquery or w/e else can be used to time between 2 different buttons being clicked.
I know how it can be done in the controller but as I need to collect 3 separate times and can't have it being done over 3 separate actions/db saves.
So far all I've found is reference to you having already set a time on it and then that acts as a countdown rather than a stopwatch.
Any help would be much appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为此,您不需要
jQuery
。您可以像这样获取当前自 The-Epoch 以来的毫秒值:或者,如果您喜欢字符计数:
只需执行两次,然后从第二次中减去第一次。唯一可能涉及 jQuery 的地方是挂钩按钮上的点击,例如:
You don't need
jQuery
for this. You can get the current milliseconds-since-The-Epoch value like this:Or if character-counting is your thing:
Just do it twice and subtract the first from the second. The only place jQuery might be involved would be hooking the clicks on the buttons, e.g.:
这是一个演示: http://jsfiddle.net/wwnyY/1/
然后你可以迭代您保存的点击数组,或将其发送到服务器端脚本以存储以供以后使用。
以下是
Date()
的一些不错的文档:https: //developer.mozilla.org/en/JavaScript/Reference/Global_Objects/DateHere is a demo: http://jsfiddle.net/wwnyY/1/
You can then iterate through your array of saved clicks, or send it to a server-side script to store for later use.
Here are some good docs for
Date()
: https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Date