只有在甜蜜警报关闭后,我才能将焦点放在页面中的文本框上。这是我正在使用的代码
swal({
title:'Student Already Logged In!',
text: 'Student already logged in.',
type: 'warning',
timer: 2500,
showConfirmButton: false
});发布于 2018-08-17 08:39:16
如果您使用的是SweetAlert2,则需要添加一个带有myElement.focus();的promise,如documentation中所述。
例如,您的textBox有id='my-input',您需要的JS代码是:
(function() {
swal({
title: 'Student Already Logged In!',
text: 'Student already logged in.',
type: 'warning',
timer: 2500,
showConfirmButton: false
}).then(function() {
document.getElementById('my-input').focus();
});
})()<script src="https://cdnjs.cloudflare.com/ajax/libs/sweetalert/2.1.0/sweetalert.min.js"></script>
<input type="text" id="my-input">
或者,如果您使用的是SweetAlert (v1.x),则需要将回调作为swal()的第二个参数进行传递。
swal({
title: 'Student Already Logged In!',
text: 'Student already logged in.',
type: 'warning',
timer: 2500,
showConfirmButton: false
}, function() {
document.getElementById('my-input').focus();
});https://stackoverflow.com/questions/51886834
复制相似问题