【问题标题】:When clicks on close button it should stop redirecting using alertify?当单击关闭按钮时,它应该停止使用 alertify 进行重定向?
【发布时间】:2018-07-31 06:44:23
【问题描述】:

当我单击关闭按钮时,它正在重定向到个人资料页面。但它进入onclose 事件部分,它不应该像returns false 那样刷新页面,而是重定向到个人资料页面。

alertify.alert().setting({
                'title': 'Message',
                'label': 'Ok',
                'message': 'You have not yet enabled Appointment on your profile?',
                'onok': function () {
                    document.location.href = "/profile";
                },
                'onclose':function(e){
                   return false;//It should stop redirecting on profile page
                }
            }).show();

错误:当我点击OkClose(X) 时,两个事件都在触发。

谢谢。

【问题讨论】:

    标签: javascript alertify alertifyjs


    【解决方案1】:

    根据alertify 的文档,这是alert onok 事件的默认功能。

    所以当onok事件在alert中被调用时,它会自动调用onclose事件来关闭对话框。

    【讨论】:

    • onokonclose 可以单独调用吗?或者还有其他解决方案。
    • 当您需要onokonclose 单独工作时,最好在这种情况下使用confirm 对话框。
    • 非常感谢。
    【解决方案2】:

    使用

     'onclose':(e)=>{
        e.preventDefault();    //It will stop redirecting on profile page
        return false;//
    }
    

    【讨论】:

    • 感谢您的回答。它给出了一个错误uncaught typeerror cannot read property 'preventdefault' of undefined
    • console.log(e)
    • 我已经更新了代码,我使用箭头函数来解决绑定问题,如果有请使用更新的代码
    • 我需要查看你的整个代码,请给我链接以访问它,在这里分享
    • 这是工作代码,当页面加载时会打开一个弹出窗口。可以点击确定或关闭按钮。
    猜你喜欢
    • 2015-10-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-18
    • 2022-08-10
    相关资源
    最近更新 更多