我有一个带有一个继续按钮的页面。如果我点击继续那么
如果我为弹出窗口单击“确定”,则所有上述3个弹出窗口都会出现,但是如果我在弹出窗口中单击“取消”,则页面应该关闭,这是通过我的closeAction();
方法完成的。
如果我点击取消第一个或第二个弹出窗口,页面没有关闭,但第三个工作。
if(document.getElementById(id1).value){
if(!confirm("click Cancel to Close page and ok to go to next popup")){
closeAction();
}
}
if(document.getElementById(id2).value){
if(!confirm("click Cancel to Close page and ok to go to next popup")){
closeAction();
}
}
if(!confirm(" to be made click 'Cancel'")){
closeAction();
}
答案 0 :(得分:1)
使用else,以便在调用closeAction方法后跳过其余检查:
if (document.getElementById(id1).value && !confirm("click Cancel to Close page and ok to go to next popup")) {
closeAction();
} else if (document.getElementById(id2).value && !confirm("click Cancel to Close page and ok to go to next popup")) {
closeAction();
} else if (!confirm(" to be made click 'Cancel'")) {
closeAction();
}
答案 1 :(得分:0)
请记住,&&
正在短路:
if (document.getElementById(id1).value &&
!confirm("click Cancel to Close page and ok to go to next popup") &&
document.getElementById(id2).value &&
!confirm("click Cancel to Close page and ok to go to next popup") &&
!confirm(" to be made click 'Cancel'"))
{
closeAction();
}