页面完成加载后,我尝试将SweetAlert2用作“弹出框”。 “弹出框”叠加层下面是正常内容。
我怎样才能做到这一点?
参考:
How to add event listener for html buttons in sweetalert dialog box in jquery
`http://codepen.io/html5andblog/pen/jPzPWj` (this is good but it doesn't onload and redirect)
答案 0 :(得分:0)
这是你的作业;) [JSFIDDLE]
swal({
html:
'<a href="http://example1.com" id="link1" target="_blank">link 1</a><br>' +
'<a href="http://example2.com" id="link2" target="_blank">link 2</a>',
confirmButtonText: 'Continue >',
allowOutsideClick: false,
allowEscapeKey: false
});
// disable "Continue >" button on load
swal.disableButtons();
// handle clicks and enable "Continue >" button when all links are clicked
var clickedLinks = [];
$('body').on('click', '.swal2-modal a', function(e) {
var link = e.target;
if (clickedLinks.indexOf(link) === -1) {
clickedLinks.push(link);
}
// when all links are clicked enable "Continue >" button
if (clickedLinks.length === $('.swal2-modal a').size()) {
swal.enableButtons();
}
});