javascript終止函數(shù)執(zhí)行操作_javascript技巧
來源:懂視網(wǎng)
責(zé)編:小采
時(shí)間:2020-11-27 21:19:39
javascript終止函數(shù)執(zhí)行操作_javascript技巧
javascript終止函數(shù)執(zhí)行操作_javascript技巧:1、如果終止一個(gè)函數(shù)的用return即可,實(shí)例如下:function testA(){ alert('a'); alert('b'); alert('c');}testA(); 程序執(zhí)行會(huì)依次彈出'a','b','c'。 function testA(){ alert('a'); return; alert('b'); aler
導(dǎo)讀javascript終止函數(shù)執(zhí)行操作_javascript技巧:1、如果終止一個(gè)函數(shù)的用return即可,實(shí)例如下:function testA(){ alert('a'); alert('b'); alert('c');}testA(); 程序執(zhí)行會(huì)依次彈出'a','b','c'。 function testA(){ alert('a'); return; alert('b'); aler

1、如果終止一個(gè)函數(shù)的用return即可,實(shí)例如下:
function testA(){
alert('a');
alert('b');
alert('c');
}
testA(); 程序執(zhí)行會(huì)依次彈出'a','b','c'。
function testA(){
alert('a');
return;
alert('b');
alert('c');
}
testA(); 程序執(zhí)行彈出'a'便會(huì)終止。
2、在函數(shù)中調(diào)用別的函數(shù),在被調(diào)用函數(shù)終止的同時(shí)也希望調(diào)用的函數(shù)終止,實(shí)例如下:
function testC(){
alert('c');
return;
alert('cc');
}
function testD(){
testC();
alert('d');
}
testD(); 我們看到在testD中調(diào)用了testC,在testC中想通過return把testD也終止了,事與愿違return只終止了testC,程序執(zhí)行會(huì)依次彈出'c','d'。
function testC(){
alert('c');
return false;
alert('cc');
}
function testD(){
if(!testC()) return;
alert('d');
}
testD(); 兩個(gè)函數(shù)做了修改,testC中返回false,testD中對testC的返回值做了判斷,這樣終止testC的同時(shí)也能將testD終止,程序執(zhí)行彈出'c'便會(huì)終止。
聲明:本網(wǎng)頁內(nèi)容旨在傳播知識(shí),若有侵權(quán)等問題請及時(shí)與本網(wǎng)聯(lián)系,我們將在第一時(shí)間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com
javascript終止函數(shù)執(zhí)行操作_javascript技巧
javascript終止函數(shù)執(zhí)行操作_javascript技巧:1、如果終止一個(gè)函數(shù)的用return即可,實(shí)例如下:function testA(){ alert('a'); alert('b'); alert('c');}testA(); 程序執(zhí)行會(huì)依次彈出'a','b','c'。 function testA(){ alert('a'); return; alert('b'); aler