How to stop execution of javascript: 1. Open the corresponding js code file; 2. Terminate function execution through the return method, code such as "function testA(){alert('a');return;alert( 'b');}".
The operating environment of this article: windows7 system, javascript version 1.8.5, DELL G3 computer
How to stop the execution of javascript?
javascript Terminate function execution operation
1. If you want to terminate a function, just use return. The example is as follows:
function testA(){ alert('a'); alert('b'); alert('c'); }
testA(); When the program is executed, 'a', 'b', and 'c' will pop up in sequence.
function testA(){
alert('a');
return;
alert('b') ;
alert('c');
}
testA(); Program execution will terminate when 'a' pops up.
2. When calling other functions within a function, when the called function terminates, the calling function is also expected to terminate. The example is as follows:
function testC(){ alert('c'); return; alert('cc'); } function testD(){ testC(); alert('d'); }
testD(); We see that in testD TestC was called. In testC, I wanted to terminate testD through return. However, contrary to expectations, return only terminated testC. When the program is executed, 'c' and 'd' will pop up in sequence.
function testC(){
alert('c');
return false;
alert('cc');
}
function testD(){
if(!testC()) return;
alert('d');
}
testD(); The two functions have been modified. TestC returns false, and testD judges the return value of testC. In this way, when testC is terminated, testD can also be terminated, and 'c' pops up when the program is executed. will terminate.
Recommended study: "javascript basic tutorial"
The above is the detailed content of How to stop execution of javascript. For more information, please follow other related articles on the PHP Chinese website!