gpt4 book ai didi

javascript - CSS Bootstrap 关闭模态并转到链接

转载 作者:太空宇宙 更新时间:2023-11-03 20:40:16 25 4
gpt4 key购买 nike

我有以下模态框的 div -

<div class="modal fade" id="Community" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-content">
<button type="button" onclick="window.location.href='#Pricing'" data-dismiss="modal">Close and go to pricing</button>
</div>
</div>

单击按钮时,模态窗口关闭,但不会转到#Pricing 指示的正确部分。

最佳答案

您在 onclick 中缺少一个 '

<button type="button" onclick="window.location.href='#Pricing'" data-dismiss="modal">Close and go to pricing</button>

更新

我想我知道原因了。实际上,在您的情况下,onclickdata-dismiss="modal" 之前触发。这意味着,位置更改甚至会在模态解雇之前发生。但是,为了防止页面在模式出现时滚动,主体将有一个 modal-open 类。这需要 overflow: hidden;,因此页面将无法滚动超过模式本身的高度。

要解决此问题,您需要将位置更改推迟到模态消失之后。您可以将其移动到 hidden.bs.modal 事件的回调中。

事件文档可以在这里找到:http://getbootstrap.com/javascript/#modals-usage .

关于javascript - CSS Bootstrap 关闭模态并转到链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27118838/

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