【问题标题】:Page should refresh when click cancel on confirm box单击确认框上的取消时页面应刷新
【发布时间】:2019-01-07 18:39:36
【问题描述】:
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;
        }

【问题讨论】:

  • 使用location.reload()刷新页面。
  • 你有什么问题?

标签: javascript visualforce confirm


【解决方案1】:

您应该检查用户点击了什么,而不是返回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();
  }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-09-02
    • 1970-01-01
    • 1970-01-01
    • 2016-09-26
    • 2014-04-10
    • 2012-07-12
    • 2015-07-05
    相关资源
    最近更新 更多