本文介绍了检查按钮“没有”在一定时间内被点击(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)
发布评论