我遇到了如下情况。 发生了一些事情,用户需要决定是否继续。 如果他不这样做,代码就会停止执行。 如果他这样做,事情就会继续下去。
但是,我希望当顶部的 if 语句返回 false 时也执行该部分(大量代码),而不是两次使用相同的代码。
在 VB 中我会使用 GOTO,但在 Javascript 中没有等效的。
if(true){
var r = confirm("although this and that... do you still want to continue?");
if (r == false) {
break;
} else {
a lot of code
}
}
有什么想法吗?
最佳答案
创建一个函数
function confirmPop(){
if(true){
var r = confirm("although this and that... do you still want to continue?");
if (r == false) {
break;
} else {
a lot of code
}
}
}
然后调用
confirmPop();
关于javascript - 在 JavaScript 中使用相同的代码两次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31317713/