欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

javascript 終止函數(shù)執(zhí)行操作

 更新時間:2014年02月14日 08:58:43   作者:  
本篇文章主要是對javascript 終止函數(shù)執(zhí)行的操作方法進行了介紹,需要的朋友可以過來參考下,希望對大家有所幫助

1、如果終止一個函數(shù)的用return即可,實例如下:
function testA(){
    alert('a');
    alert('b');
    alert('c');
}
testA(); 程序執(zhí)行會依次彈出'a','b','c'。

function testA(){
    alert('a');
    return;
    alert('b');
    alert('c');
}
testA(); 程序執(zhí)行彈出'a'便會終止。

2、在函數(shù)中調(diào)用別的函數(shù),在被調(diào)用函數(shù)終止的同時也希望調(diào)用的函數(shù)終止,實例如下:
function testC(){
    alert('c');
    return;
    alert('cc');
}

function testD(){
    testC();
    alert('d');
}
testD(); 我們看到在testD中調(diào)用了testC,在testC中想通過return把testD也終止了,事與愿違return只終止了testC,程序執(zhí)行會依次彈出'c','d'。

function testC(){
    alert('c');
    return false;
    alert('cc');
}

function testD(){
    if(!testC()) return;
    alert('d');
}
testD(); 兩個函數(shù)做了修改,testC中返回false,testD中對testC的返回值做了判斷,這樣終止testC的同時也能將testD終止,程序執(zhí)行彈出'c'便會終止。

相關(guān)文章

最新評論