检查函数是否返回true以执行另一个函数 [英] Check if function returns true to execute another function
本文介绍了检查函数是否返回true以执行另一个函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我用JS编写了一个表单验证,以return(true)结尾;
I have written a form validation using JS which ends with return(true);
function check() {
....validation code
return(true);
}
我想要的是,需要检查check()函数是否返回true,我想执行另一个函数。
All I want is, need to check if check() function returns true, I want to execute another function.
我试过的代码如下:
if(check() === true) {
function() {
//Another function code
}
}
推荐答案
你应该使用 return true;
并且你的if语句不需要 === true
比较。
You should use return true;
and your if statement doesn't need the === true
comparison.
function check() {
//validation code
return true;
}
if(check()) {
//Another function code
}
JSFIDDLE
这篇关于检查函数是否返回true以执行另一个函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文