Javascript Jquery - 停止脚本在 if 条件下执行

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13637245/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-24 12:33:26  来源:igfitidea点击:

Jquery - stop script executing on if condition

javascriptjquery

提问by Sasha

How can I stop script executing when if condition is met? Is it possible to do it without else? For example:

如果满足条件,如何停止脚本执行?没有别的可以做到吗?例如:

if(data == 'false')
{
stop
}
rest of the function...

回答by Blender

You can return out of the function:

您可以从函数中返回:

if (data == 'false') {
    return false;
}