简体   繁体   English

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

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

I need to have a message to be alerted as follows : 我需要有一条消息被警告,如下所示:

If the user clicks on ok button aka accept button the page should be redirected to next page and if the user clicks on go/back button it should redirect to the previous page, Can someone suggest anything on this matter thanks. 如果用户单击“确定”按钮又称为“接受”按钮,则该页面应重定向到下一页;如果用户单击“转到/返回”按钮,则应重定向到上一页。有人可以对此提出建议吗,谢谢。

At present i need to alert following meesage : 目前,我需要提醒以下消息:

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;
}

assuming a link wired up on click: 假设在点击时链接了一个链接:

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
  }
}

using 运用

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

You're looking for confirm() , not alert() 您正在寻找的是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);
    }
}

The History API is only supported in IE10 and up 仅在IE10及更高版本中支持History API

Use confirm . 使用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.

相关问题 单击按钮时,转到下一页并刷新上一个Jquery Mobile - When clicking a button go to next page and refresh the previous one Jquery Mobile 单击按钮后刷新页面(确定/取消) - Refresh page after clicking button (ok / cancel) 在 confirm() 方法中单击“取消”与单击“确定”具有相同的结果 - Clicking 'cancel' in confirm() method has the same result as clicking 'ok' 单击按钮时转到html页面中的下一个位置-jQuery - Go to next position in html page when clicking a button - jquery 如何通过单击下一步按钮使用Angular js转到具有不同数据的同一页面到laravel - how to go to same page with different data into laravel using angular js by clicking next button 在单击指向 go 的箭头时,使用 javascript 为 svg 着色到下一张幻灯片 - Coloring svg using javascript when clicking an arrow to go to the next slide 单击锚点应该执行javascript而不是转到新页面 - Clicking anchor should execute javascript not go to new page Cakephp 2,返回/取消按钮转到上一页 - Cakephp 2, back/cancel button to go to the previous page 为什么点击链接会跳转到页面顶部? - Why does clicking a link go to the top of the page? 点击链接后如何go到页面顶部? - How to go to the top of the page after clicking the link?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM