简体   繁体   English

jQuery关闭模态问题

[英]Jquery close modal issue

Ok so i have a modal in bootstrap that has the class of show, to have it display on page load. 好的,所以我在引导程序中有一个具有show类的模态,使其在页面加载时显示。 So it has a ender button at the bottom but couldnt get it to close on click 所以它的底部有一个渲染器按钮,但是单击后无法关闭

So I now have script that closes if clicks any where on the box but really it only on that button 所以我现在有一个脚本,如果单击框上的任何位置,则关闭,但实际上仅在该按钮上单击

JS JS

<script> 
  $('.modal').click(function() { 
    $(this).removeClass('show'); 
    $(this).addClass('hide');
  }); 
</script>

Modal box classes 模态箱类

<div class="modal show"></div>

Button 按键

<button type="button" class="btn btn-primary center-block click" style="font-size: 20px;" onClick='changeClass'">ENTER</button>

Any help would be great! 任何帮助将是巨大的!

This doesn't work that way. 这样是行不通的。 You only have to $('.modal .close').modal("hide"); 您只需要$('.modal .close').modal("hide");

.close being the class for your close button. .close是关闭按钮的类。

Or you can add attribute data-dismiss="modal" to close button. 或者,您可以将属性data-dismiss="modal"到关闭按钮。

Ref: http://getbootstrap.com/javascript/#modals-methods 参考: http : //getbootstrap.com/javascript/#modals-methods

If you are using bootstrap you can do this to close and show a modal: 如果您正在使用引导程序 ,则可以执行以下操作以关闭并显示模式:

$('.modal').modal('toggle');

Check out the documentation here . 此处查看文档。

Also note that bootstrap has an out of the box close button (which you need to include inside your modal) to handle this behavior: 还要注意, 引导程序具有开箱即用的关闭按钮(您需要在模态中包括该按钮)来处理此行为:

<button type="button" class="close" data-dismiss="modal">x</button> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM