javascript – 在Bootstrap Modal关闭时关注输入
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了javascript – 在Bootstrap Modal关闭时关注输入,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1849字,纯文字阅读大概需要3分钟。
内容图文
在输入字段“bootbox1”上出现模糊事件后,我想在消息模式关闭时使用Bootstrap Modal作为消息,将转到输入字段“bootbox2”.但是输入字段没有得到关注.
我究竟做错了什么?
HTML
<input type="text" id="bootbox" />
<input type="text" id="bootbox2" />
<div id="myModal" class="modal fade">
<div class="modal-dialog">
<div class="modal-content">
<!-- dialog body -->
<div class="modal-body">
<button type="button" class="close" data-dismiss="modal">×</button>Hello world!</div>
<!-- dialog buttons -->
<div class="modal-footer">
<button type="button" class="btn btn-primary">OK</button>
</div>
</div>
</div>
</div>
JS
$('#bootbox').on('blur', function checkSelection(e) {
$("#myModal").on("show", function () { // wire up the OK button to dismiss the modal when shown
$("#myModal a.btn").on("click", function (e) {
console.log("button pressed"); // just as an example...
$("#myModal").modal('hide');
$('#bootbox2').focus();
// dismiss the dialog
});
});
$("#myModal").on("hide", function () { // remove the event listeners when the dialog is dismissed
$("#myModal a.btn").off("click");
$('#bootbox2').focus();
});
$("#myModal").on("hidden", function () { // remove the actual elements from the DOM when fully hidden
$("#myModal").remove();
});
$("#myModal").modal({ // wire up the actual modal functionality and show the dialog
"backdrop": "static",
"keyboard": true,
"show": true // ensure the modal is shown immediately
});
});
//this works
$('#bootbox2').on('blur', function checkSelection(e) {
$('#bootbox').focus();
});
解决方法:
您需要等待hidden.bs.modal事件触发,而不是hide.bs.modal.
根据事件hide.bs.modal的Bootstrap Docs
This event is fired immediately when the hide instance method has been
called.
而hidden.bs.modal
This event is fired when the modal has finished being hidden from the
user (will wait for CSS transitions to complete).
由于在移除叠加层之前调用了焦点,因此输入无法获得键盘焦点.
内容总结
以上是互联网集市为您收集整理的javascript – 在Bootstrap Modal关闭时关注输入全部内容,希望文章能够帮你解决javascript – 在Bootstrap Modal关闭时关注输入所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。