javascript - 单击确认框上的取消时页面应刷新
问题描述
return confirm('Changing the protocol will reset the project Team members');
}
我在onclick上调用了两种方法,第一种是停止多次单击按钮,第二种是显示确认框。一旦用户点击取消,用户将无法再次保存。我正在寻找在点击时区分这两种肉类的解决方案。
<apex:commandButton onclick=" this.onclick=function(){return false;}; return showProtocolEditWarning();" action="{!save}" value="Save" id="commandButtonSave"/>
function showProtocolEditWarning(){
if(projectId && praProtocol){
var newProject = document.querySelector('input[id$="inputFieldPraProject_lkid"]').value;
var protocolIdElement = document.querySelector('select[id$="protocolIdList"]');
var newProtocol = protocolIdElement.options[protocolIdElement.selectedIndex].value;
if(praProject.substring(0,15) != newProject.substring(0,15) || praProtocol != newProtocol){
return confirm('Changing the protocol will reset the project Team members');
//window.location.reload() ;
}
}
return true;
}
解决方案
而不是返回confirm(...)
,您应该检查用户点击的内容,location.reload()
如果用户点击取消,则使用重新加载页面:
function confirmMessage() {
if(confirm('Your confirmation msg')) { //i.e. if the user pressed ok
//handle this
}
else { //i.e. user pressed cancel
location.reload();
}
}
推荐阅读
- c++ - 使用非参考文件调用音频质量测量
- angular - Angular 6 服务依赖注入
- amazon-web-services - AWS 超出限制的通知
- android - 在 Android Studio 中运行颤振项目时出现 Gradle 错误
- tortoisegit - 在 TortoiseGit 2.7.0 中使用旧的 Git 会破坏什么?
- android - 升级到 Android Studio 3.2 正在创建 Aapt2Exception
- c# - 使用 XDocument 使用 C# 从 XML 读取根元素不显示根元素
- javascript - “包含”Javascript 函数在 WSO2 ESB 脚本中介中不起作用
- .net - Web api 2 (.net core) 服务已部署在 azure 服务器门户中,获取端点响应在 1 分钟内过期
- mysql - 需要合并此查询