2017-04-25 133 views
1

我到目前为止的代码,把我送到某个网页:

甜警报2和javascript:如何使一个甜蜜的警报按钮,当按下

swal({ 
    title: 'Successfully Registered!', 
    text: "Do you want to go to the Log In page?", 
    type: 'success', 
    showCancelButton: true, 
    confirmButtonColor: '#3085d6', 
    cancelButtonColor: '#d33', 
    confirmButtonText: 'Yes, send me there!' 
    }, 
    function(){ 
     window.location.href= "http://example.com"; 
    } 
); 

出于某种原因,window.location.href是不工作,我试图只使用location.href和if(isConfirm)等。
我该怎么办?
的jsfiddle:https://jsfiddle.net/2dz868kd/

+0

您应该将代码上传到[jsfiddle](https://jsfiddle.net/),以便用户可以看到演示并可以在其中进行更改。 – Webinion

+0

我做了,谢谢你的建议。 –

回答

3

在这里你去:

swal({ 
 
    title: 'Successfully Registered!', 
 
    text: 'Do you want to go to the Log In page?', 
 
    type: 'success', 
 
    showCancelButton: true, 
 
    confirmButtonColor: '#3085d6', 
 
    cancelButtonColor: '#d33', 
 
    confirmButtonText: 'Yes, send me there!' 
 
}).then(function(result) { 
 
    if (result.value) { 
 
    location.assign("https://jsfiddle.net") 
 
    } 
 
});
<script src="https://unpkg.com/[email protected]/dist/sweetalert2.all.js"></script>

SweetAlert2文档:https://sweetalert2.github.io/

请注意,SweetAlert2和SweetAlert是两个不同的项目。 SweetAlert2使用ES6 Promises。

+1

老兄,你不知道我有多爱你!我花了太多时间试图弄清楚。 –

相关问题