点击时间延迟 [英] Time delay on click

查看:101
本文介绍了点击时间延迟的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以向我发送JavaScript代码,说明如何构建时间延迟,从单击页面上的按钮到执行按钮单击调用的功能。我是JavaScript的新手,我有一些代码,当我点击一个按钮时执行一个功能,我只想延迟时间。

Can anyone send me JavaScript code on how I can construct a time delay from the time I click a button on a page to the time the function called by the button click is executed. I am a novice with JavaScript, and I have some code that performs a function when I click a button, and I just want to have a time delay.

推荐答案

这是Javascript:

This is the Javascript:

 function myfunction() {
     alert( "delayed" );
 }

 var delay = 1000;

 setTimeout( myfunction, delay )

这就是本质。现在你需要将它挂钩到html页面上的一个按钮:将函数定义嵌入到<脚本> ... < / script> 标签,并在onClick方法中安排它。

That's the essence. Now you need to hook it into a button on a html page: embed the function definition in < script > ... < /script > tags, and schedule it in the onClick method.

....
<button onClick="setTimeout( myfunction, delay );">Click_And_Wait</button>

这篇关于点击时间延迟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆