Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/469.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 单击时在Twitter引导中隐藏模式_Javascript_Jquery_Css_Twitter Bootstrap - Fatal编程技术网

Javascript 单击时在Twitter引导中隐藏模式

Javascript 单击时在Twitter引导中隐藏模式,javascript,jquery,css,twitter-bootstrap,Javascript,Jquery,Css,Twitter Bootstrap,下面是来自twitter引导的示例代码,但是 <div class="modal"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button> <h3>Modal header</h3> &

下面是来自twitter引导的示例代码,但是

<div class="modal">
    <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
        <h3>Modal header</h3>
    </div>
    <div class="modal-body">
        <p>One fine body…</p>
    </div>
    <div class="modal-footer">
        <a href="#" class="btn">Close</a>
        <a href="#" class="btn btn-primary">Save changes</a>
    </div>
</div>

&时代;
模态头
一个好身体

场景是这样的:我有一个重定向页面,我想显示模式。是的,我当然让它显示出来了,但是我如何关闭它呢?我尝试了单击功能的不同方式,但什么也没发生。

来自bootstrap文档:

手动隐藏模式。

.modal('hide')

$('.modal').modal('hide')
因此,如果要在
单击时隐藏它,可以将此操作绑定到
单击事件

$('#yourid').on('click' , function() { 
  $('.modal').modal('hide')
});
如果您想在加载文档后几秒钟将其隐藏,您可以尝试使用
超时

$(function(){  //document ready
..
.. //your code
..

 setTimeout(function(){
       $('.modal').modal('hide')
 }, 2000);  //2000 = 2 second

..
})
更新1

要在关闭
按钮上绑定它
给他一个
id

<a href="#" class="btn closebtn">Close</a>
如果只想在
关闭
按钮上绑定,请使用
id
而不是

$('.modal').modal('hide');

我也有同样的问题。如果仍然需要,您可以尝试将您的“单击”事件放在另一个“显示.bs.dropdown”事件中,如下所示:

$('#myDropdown').on('show.bs.dropdown', function () {
  $('#yourid').on('click' , function() { 
    $('#myDropdown').modal('hide');
  });
});

在我的例子中,“click”事件在显示模式时没有绑定。所以,当我把它放在“show.bs.dropdown”活动中时,一切都如我所料“点击”一显示模式就被绑定到模式。

旧帖子,但现在可以使用HTML属性来完成

 <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
关闭

它对我不起作用。注意,重定向后的no(隐藏和淡出类)没有隐藏。您能更好地解释它吗?可能没有人真正了解你的问题。好的,例如,我在主页上,提交表单后,我将被重定向到另一个页面,该页面已经有一个模式显示此代码×;Modal header一个很好的body…

问题是如何关闭Modal?dude我编写的代码必须工作,我也使用bootstrap,它确实工作。您是否有任何控制台错误?何时要隐藏您的模式?
 <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>