我有一个按钮,点击后调用 function1 调用另一个 function2 。如果function2满足条件,它应该返回false并在那里死亡但是它继续,返回到function1,执行其余的function1并提交表单。我是javascript的新手。
<input type="button" value="Submit" onclick="function1()" />
function function1() {
function2();
//execute rest of function
}
function2() {
var this;
var that;
if(!this || !that) {
alert("You did not fill out fields on the form under Tab1");
return false; //I thought it was supposed to stop here
}
}
答案 0 :(得分:1)
在function1中调用function2时,如果你想让function1在函数2返回false时停止,那么你必须将它停在INSIDE函数1中,如下所示:
function function1() {
// If function2 returns false, then stop function1
if (!function2()) return;
//execute rest of function
}
function2() {
var this;
var that;
if(!this || !that) {
alert("You did not fill out fields on the form under Tab1");
return false; //I thought it was supposed to stop here
}
}