How to stop execution with javascript
This article introduces the relevant knowledge of "how to stop execution with javascript". In the operation of actual cases, many people will encounter such a dilemma, so 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!
The method to stop the execution of javascript: 1, open the corresponding js code file; 2, terminate the function operation through the return method, such as "function testA () {alert ('a'); return;alert ('b');}".
This article operating environment: windows7 system, javascript1.8.5 version, DELL G3 computer
How does javascript stop execution?
Javascript terminates the function to perform the operation
1. If you terminate a function, you can use return. The example is as follows:
Function testA () {alert ('a'); alert ('b'); alert ('c');}
TestA (); the execution of the program will pop up in turn: 'axiomagery', baccalaureate, etc., etc.
Function testA () {
Alert ('a')
Return
Alert ('b')
Alert ('c')
}
TestA (); the program execution will be terminated by popping up'a'.
2. Call another function in the function. When the called function terminates, the function you want to call also terminates. The example is as follows:
Function testC () {alert ('c'); return; alert ('cc');} function testD () {testC (); alert (' d');}
TestD (); We see that testC is called in testD, and testD is terminated through return in testC. Instead, return only terminates testC, and the program execution pops up "centering, writing and writing" in turn.
Function testC () {
Alert ('c')
Return false
Alert ('cc')
}
Function testD () {
If (! testC ()) return
Alert ('d')
}
TestD (); two functions have been modified, and the return value of testC is judged in the false,testD returned in testC, so that the testD can be terminated when the testC is terminated, and the program execution will be terminated by popping up'c'.
This is the end of "how to stop execution with javascript". 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!