twitter-bootstrap 单击链接后,我可以关闭 Bootstrap 模式吗?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13319678/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 15:41:27  来源:igfitidea点击:

Can I close the Bootstrap modal once the link has been clicked?

htmltwitter-bootstrapmodal-dialog

提问by user1814016

Right now, I'm using this in a Bootstrap modal to redirect to a site:

现在,我在 Bootstrap 模式中使用它来重定向到一个站点:

<a href="http://www.example.com/" href="_blank">click</a>

I want the modal to be closed once the link has been clicked, so I thought adding data-dismiss="modal"to the tag would work, however it causes the modal to close without the link being opened.

我希望一旦点击链接就关闭模态,所以我认为添加data-dismiss="modal"到标签会起作用,但是它会导致模态关闭而不打开链接。

Can I combine these and make the modal close afterthe URL opens?

我可以组合这些并在 URL 打开关闭模态吗?

回答by Skylar Ittner

This works for me and doesn't require extra script tags:

这对我有用,不需要额外的脚本标签:

<a href="http://www.example.com/" onclick="$('#myModal').modal('hide')">click</a>

回答by Mwspace LLC

in boostrap 4 :

在助推器 4 中:

<a href="http://www.example.com/" data-dismiss="modal" href="_blank">click</a>

回答by user11580136

This worked for me. <a onclick="location.href='http://www.example.com/';" data-dismiss="modal">click</a>

这对我有用。 <a onclick="location.href='http://www.example.com/';" data-dismiss="modal">click</a>

回答by ilmk

Add one id to anchor tag. Then you can close the modal using that id once it get clicked.

添加一个 id 到锚标签。然后,您可以在点击后使用该 id 关闭模式。

<a href="http://www.example.com/" href="_blank" id="sample">click</a>

<script>        
    $("a#sample").click(function(){
    $('#myModal').modal('hide')
    });
</script>

回答by Yohn

something like the following should do it

像下面这样的事情应该做

$('a').click(function(){
  $('modal-selector').modal('hide')
})

回答by Ahmed

You can use the already existing class in your element:

您可以在元素中使用现有的类:

class="modal-close"