停止模态关闭外面单击或ESC
嗨,我试图禁用外部,请单击我的模态。我尝试使用诸如背景:'static',键盘:false之类的方法,但我似乎无法使其起作用
html:
<div class="container my-5">
<hr class="my-5">
<!-- Modal -->
<div class="modal fade" id="basicExampleModal" tabindex="-1" role="dialog" aria-
labelledby="exampleModalLabel" aria-hidden="true" data-backdrop="static" data-
keyboard="false">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<center><h1 class="modal-title" id="exampleModalLabel">Want more?</h1></center>
</button>
</div>
<div class="modal-body">
<strong>Create an account or Log in to see additional search results...</strong>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Sign up</button>
<button type="button" class="btn btn-primary">Log In</button>
</div>
</div>
</div>
</div>
javaScript:
$(function() {
$('#basicExampleModal').modal('show');
});
Hi im trying to disable outside click in my modal. I've tried using methods like backdrop: 'static', keyboard: false but i cant seem to make it work
html:
<div class="container my-5">
<hr class="my-5">
<!-- Modal -->
<div class="modal fade" id="basicExampleModal" tabindex="-1" role="dialog" aria-
labelledby="exampleModalLabel" aria-hidden="true" data-backdrop="static" data-
keyboard="false">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<center><h1 class="modal-title" id="exampleModalLabel">Want more?</h1></center>
</button>
</div>
<div class="modal-body">
<strong>Create an account or Log in to see additional search results...</strong>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Sign up</button>
<button type="button" class="btn btn-primary">Log In</button>
</div>
</div>
</div>
</div>
javascript:
$(function() {
$('#basicExampleModal').modal('show');
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以使用“ data-bsbackdrop”和“ data-bs-kekeboard”属性,而不是data-backDrop =“ static” data-keyboard =“ false”。 Bootstrap 5已更改命名约定,并且数据键盘板和数据键板的属性现在以BS-为前缀。
you can use "data-bs-backdrop" and "data-bs-keyboard" attributes instead of data-backdrop="static" data-keyboard="false". Bootstrap 5 has made changes to the naming conventions, and the data-backdrop and data-keyboard attributes are now prefixed with bs-.
您发布的代码中有几个语法问题。前任。额外的
&lt;/button&gt;
标签和data-keyboard =“ false”&gt;
有一个空间。除了语法问题外,它应该按照预期的方式工作,如您从下面的示例中所见。如果您的目的仍然不起作用,则代码中其他地方还有其他问题。You have couple syntax issues in the code you posted. Ex. extra
</button>
tag anddata- keyboard="false">
has a space in it. Aside from the syntax issues, it should work as expected as you can see from below example. If it still doesn't work on your end, there is something else wrong elsewhere in your code.Bootstrap 4
Bootstrap 4
使用以下方式:
此脚本现在将通过单击模式外或按下 esc 键来关闭模式。
Use this:
This script will now allow close the modal by clicking outside the modal or by pressing the esc key.