检查按钮“没有”在一定时间内被点击(jQuery)

编程入门 行业动态 更新时间:2024-10-14 20:19:51
本文介绍了检查按钮“没有”在一定时间内被点击(jQuery)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

基本上:

您点击一个按钮,它运行功能1. 如果您在1秒内未再次点击该按钮,函数2运行。 如果在1秒内单击按钮,则它再次运行函数1. 等等...

You click a button and it runs function 1. If you don't click the button again within 1 second then function 2 runs. If you click the button within 1 second then it runs function 1 again. and so on and so forth...

我无法找出在Javascript中执行此操作的逻辑。

I can't figure out the logic to do this in Javascript.

有没有办法?

感谢高级!

推荐答案

从头开始(还没有测试过,这对我来说似乎是最逻辑的):

from the top of my head (haven't tested this, but this seems most logic to me):

var t = null; $("button").click(function() { console.log("this is function 1"); if (t !== null) { window.clearTimeout(t); } t = window.setTimeout(function() { console.log("and this is function 2"); }, 1000); });

更多推荐

检查按钮“没有”在一定时间内被点击(jQuery)

本文发布于:2023-11-27 13:33:52,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1638288.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:时间内   在一   按钮   jQuery

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!