繁体   English   中英

在警报中,单击“确定”转到下一页,单击“取消”必须使用javascript转到上一页

[英]in alert clicking ok has go to next page and clicking on cancel has to go to previous page using javascript

我需要有一条消息被警告,如下所示:

如果用户单击“确定”按钮又称为“接受”按钮,则该页面应重定向到下一页;如果用户单击“转到/返回”按钮,则应重定向到上一页。有人可以对此提出建议吗,谢谢。

目前,我需要提醒以下消息:

if(total < total1){
    alert('Total Grants & Others Spending should be LESS THAN Total State Tourism Office Spend Funding')
    return false;
}
if (confirm("something")) return true;
else {
  history.back();
  return false;
}

假设在点击时链接了一个链接:

window.onload=function() {
  document.getElementById("accept").onclick=function() {
    var total = ..., total1=...;
    if (total < total1) {
      if (confirm('Total Grants & Others Spending should be LESS THAN Total State Tourism Office Spend Funding. Continue anyway?')) {
        return true; 
      }
      else { 
        history.back(); 
        return false;
      }
    }
    return true; // total was ok
  }
}

运用

<a href="nextpage.html" id="accept">Accept</a>

您正在寻找的是confirm() ,而不是alert()

if(total < total1) {
    var redirect = confirm('Total Grants & Others Spending should be LESS THAN Total State Tourism Office Spend Funding');

    if (redirect) {
         window.location.href = 'nextpage.html';
    }else{
         window.history.back();
         // or window.history.go(-1);
    }
}

仅在IE10及更高版本中支持History API

使用confirm

var r = confirm('Total Grants & Others Spending should be LESS THAN Total State Tourism Office Spend Funding');
                if (r == true) {
                    // do if yes,
                } else {
                    // do if no.
                    return false;
                }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM