我需要收到如下警告的消息:
如果用户点击确定按钮又名接受按钮,页面应该被重定向到下一页,如果用户点击进入/返回按钮,它应该重定向到上一页,有人可以就此事提出任何建议,谢谢。
目前我需要警惕以下情况:
if(total < total1){
alert('Total Grants & Others Spending should be LESS THAN Total State Tourism Office Spend Funding')
return false;
}
答案 0 :(得分:1)
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>
答案 1 :(得分:0)
您正在寻找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及更高版本中支持历史记录API
答案 2 :(得分:0)
使用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;
}