您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

javascript怎么停止执行

2024/5/3 14:08:49发布47次查看
javascript停止执行的方法:1、打开相应的js代码文件;2、通过return方法终止函数执行操作,代码如“function testa(){alert('a');return;alert('b');}”。
本文操作环境:windows7系统、javascript1.8.5版、dell g3电脑
javascript怎么停止执行?
javascript 终止函数执行操作
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怎么停止执行的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product