1、终止一个函数用return即可
- function testA(){
- alert('a');
- alert('b');
- alert('c');
- }
- testA(); 程序执行会依次弹出'a','b','c'。
- function testA(){
- alert('a');
- return;
- alert('b');
- alert('c');
- }
- testA(); 程序执行弹出'a'便会终止。
- function testC(){
- alert('c');
- return;
- alert('cc');
- }
-
- function testD(){
- testC();
- alert('d');
- }
- function testC(){
- alert('c');
- return false;
- alert('cc');
- }
- function testD(){
- if(!testC()) return;
- alert('d');
- }