简体   繁体   English

使用没有设置超时的 JQuery 延迟 Function

[英]Delay a Function Using JQuery without settimeout

I'm a beginner to coding and I've been trying to delay a button click function using timeout but it seems like not working.我是编码的初学者,我一直在尝试使用超时延迟按钮单击 function ,但它似乎不起作用。

To clarify it further, this button is supposed to do something, but when I add timeout function all it does is just delay it and not processing to the next line.为了进一步澄清,这个按钮应该做一些事情,但是当我添加超时 function 时,它所做的只是延迟它而不是处理到下一行。 Even with JavaScript is okay.即使使用 JavaScript 也可以。 Can anyone help me out.谁能帮我吗。 Thanks in advance.提前致谢。 :) :)

 $(document).ready(function () { setTimeout(function(){ $("#mybutton").click(myButtonClicked); }, 1000); getURLParameter("run") && $("#mybutton").click() }); function getURLParameter(a) { a = (new RegExp("[?|&]" + a + "=([^&;]+?)(&|#|;|$)")).exec(location.search); if (null == a) return null; a = a[1]; a = a.replace(/\+/g, "%20"); return decodeURIComponent(a) } function myButtonClicked() { disableMyButton(); var a = $(".new").toArray(), c = $(".status").toArray(); a.reverse(); c.reverse(); doNextBox(a, c) }

What I'm trying to do is我想做的是

  1. Click button点击按钮
  2. Wait a second等一等
  3. Proceed to the next task继续下一个任务

Call setTimeout in your 'click'-eventhandler, pass a function and the time after that this function should be executed...在你的'click'-eventhandler 中调用setTimeout ,传递一个 function 和之后这个 function 应该被执行的时间......

Example:例子:

$('#mybutton').click(function() {
   setTimeout(doAfterTimeout, 1000);
});

function doAfterTimeout() {
  console.log('test');
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM