首页 > 解决方案 > 单击确认框上的取消时页面应刷新

问题描述

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

标签: javascriptvisualforceconfirm

解决方案


而不是返回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();
  }
}


推荐阅读