手机
当前位置:查字典教程网 >编程开发 >Javascript教程 >javascript 终止函数执行操作
javascript 终止函数执行操作
摘要:1、如果终止一个函数的用return即可,实例如下:functiontestA(){alert('a');alert('b');alert(...

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'便会终止。

2、在函数中调用别的函数,在被调用函数终止的同时也希望调用的函数终止,实例如下:

function testC(){

alert('c');

return;

alert('cc');

}

function testD(){

testC();

alert('d');

}

testD(); 我们看到在testD中调用了testC,在testC中想通过return把testD也终止了,事与愿违return只终止了testC,程序执行会依次弹出'c','d'。

function testC(){

alert('c');

return false;

alert('cc');

}

function testD(){

if(!testC()) return;

alert('d');

}

testD(); 两个函数做了修改,testC中返回false,testD中对testC的返回值做了判断,这样终止testC的同时也能将testD终止,程序执行弹出'c'便会终止。

【javascript 终止函数执行操作】相关文章:

JavaScript中指定函数名称的相关方法

javascript实现链接单选效果

JavaScript获得url查询参数的方法

javascript实现查找数组中最大值方法汇总

JavaScipt中Function()函数的使用教程

JavaScript中用sort()方法对数组元素进行排序的操作

JavaScript中isPrototypeOf函数作用和使用实例

javascript实现树形菜单的方法

javascript动态创建表格及添加数据实例详解

javascript实现控制的多级下拉菜单

精品推荐
分类导航