gpt4 book ai didi

firefox - 如何防止在引导模式中失去焦点?

转载 作者:行者123 更新时间:2023-12-02 09:30:13 32 4
gpt4 key购买 nike

看看 boostrap 网站本身:

http://getbootstrap.com/javascript/#modals-related-target

虽然这与本段的主题无关,但您可以打开一个带有输入字段的模式并尝试以下操作:聚焦一个输入字段,键入一些字符,切换到另一个窗口或浏览器选项卡,然后来回到模式。在 Firefox 中,聚焦输入不再聚焦。

如何重新聚焦最后聚焦的元素?或者我怎样才能防止焦点丢失?

更新:提交了一个问题 on GitHub .

最佳答案

除了@SHAZ 解决方案,您还需要 $(window).focus() 函数来在浏览器选项卡处于事件状态时聚焦输入

$(function(){
$('#myModal').on('shown.bs.modal', function () {
$('#myTextId').focus()
});
});

$(window).focus(function () {
var input = document.getElementById("myTextId").focus();
});
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />

<!-- Button trigger modal -->
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#myModal">
Launch demo modal
</button>

<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<h4 class="modal-title" id="myModalLabel">Modal title</h4>
</div>
<div class="modal-body">
<input type="text" id="myTextId" class="form-control" autofocus/>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
</div>
</div>


<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>

Fiddle

关于firefox - 如何防止在引导模式中失去焦点?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33970707/

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