How to implement JS termination

Source: Internet
Author: User

There are several possibilities for terminating JS operations:

1. There are two ways to terminate a function's operation

(1) Using return in the function, the function terminates execution when the return is encountered, and control continues to run down

(2) Use Try-catch exception handling in function, throw exception with throw when end is required

function Getrectarea (width, height) {  if (IsNaN (width) | | IsNaN (height)) {    throw "Parameter is not a number!";  }} try {  Getrectarea (3, ' A ');} catch (e) {  console.log (e);  Expected output: "Parameter is not a number!"}

2. The way to stop animation effects from running is by using the Stop method

(1) Stop ([Clearqueue], [gotoend]): Stops all animations that are running on the specified element

(2) If there is an animation waiting to be executed in the queue (and Clearqueue is not set to true), it will be executed immediately

3. How to terminate form submission: Use return false in form submission events, prevent form submission

4. How to terminate the timing function execution: Use Window.clearinterval (Timer object) or Window.cleartimeout (Timer object), can terminate the executing timer

How to implement JS termination

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.