Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How does jquery stop settimeout

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

This article introduces the knowledge of "how to stop settimeout by jquery". In the operation of actual cases, many people will encounter such a dilemma. Next, let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

In jquery, you can stop settimeout with the clearTimeout () method, which is used to cancel the timeout set by the setTimeout () method. The parameter must be the ID value returned by setTimeout (), and the syntax is "clearTimeout (ID value)".

The operating environment of this tutorial: windows10 system, jquery3.2.1 version, Dell G3 computer.

How does jquery stop settimeout?

The clearTimeout () method cancels the timing operation set by the setTimeout () method.

Cancel the timeout set by the setTimeout () method

The argument to the clearTimeout () method must be the ID value returned by setTimeout ().

Note: to use the clearTimeout () method, use global variables when creating and performing scheduled operations:

MyVar = setTimeout ("javascript function", milliseconds)

If the method has not been executed, we can use clearTimeout () to block it.

ClearTimeout (id_of_settimeout)

The return value obtained when id_of_setinterval calls the setTimeout () function. Using the return identifier as an argument, you can cancel the scheduled execution operation set by the setTimeout ().

Examples are as follows:

one hundred and twenty three

Click the button and wait 3 seconds before popping up "Hello".

Click the second button to prevent the execution of the pop-up function myFunction. (you must click 3 seconds ago)

Block popup of var myVar;function myFunction () {myVar = setTimeout (function () {alert ("Hello")}, 3000);} function myStopFunction () {clearTimeout (myVar);}

Output result:

If you click only the first button, a pop-up window will appear three seconds later:

If the second button is clicked within three seconds after the first button is clicked, no pop-up window will appear.

This is the end of "how to stop jquery settimeout". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report