gpt4 book ai didi

javascript - 仅在甜蜜警报关闭后自动对焦

转载 作者:行者123 更新时间:2023-11-30 20:16:19 25 4
gpt4 key购买 nike

只有在甜蜜警报关闭后,我才能将注意力集中在页面中的文本框上。这是我正在使用的代码

swal({
title:'Student Already Logged In!',
text: 'Student already logged in.',
type: 'warning',
timer: 2500,
showConfirmButton: false
});

最佳答案

如果您使用的是 SweetAlert2,则需要使用 myElement.focus(); 添加 promise ,如 documentation 中所述。 .

例如你的文本框有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();
});

关于javascript - 仅在甜蜜警报关闭后自动对焦,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51886834/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com