setInterval 函数的问题 - 尝试制作数字演示网页

发布于 2024-11-19 07:48:37 字数 1468 浏览 2 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

找个人就嫁了吧 2024-11-26 07:48:37

每当您在 $('li.item').live('click' 中处理点击时,您需要停止前一个间隔计时器并设置一个新的。这将防止速率增加,因为您有多个间隔计时器正在运行。您必须将 setInterval 的结果存储在适当范围的实例变量中,以便您可以在设置新计时器之前在下次单击时调用clearInterval,这将确保您不会为同一对象同时运行多个计时器。 。

在$('li.item').live('click', 变量 btnclicked 并不总是被定义,这使得函数的其余部分无法执行。

我不明白你关于时间变量的问题。也许你可以更具体关于哪个函数、哪段代码或者时间变量发生了什么。

Whenever you process a click in $('li.item').live('click', you need to stop the previous interval timer and set a new one. This will keep the rate from increasing because you have multiple interval timers running. You will have to store the result from setInterval in an appropriately scoped isntance variable so you can call clearInterval with it on the next click before setting a new timer. This will makes sure you don't have multiple timers running at once for the same object.

In $('li.item').live('click', the variable btnclicked is not always defined which keeps the rest of the function from executing.

I don't understand your question about the time variable. Perhaps you could be more specific about which function and which piece of code or what is happening with the time variable.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文