了解data-dismiss属性在Bootstrap中的工作原理 [英] Understanding how data-dismiss attribute works in Bootstrap

查看:203
本文介绍了了解data-dismiss属性在Bootstrap中的工作原理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Bootstrap的新手,我遇到了这个例子的问题:

I'm new to Bootstrap and i'm facing problem with this example:

<!-- Trigger the modal with a button -->
<button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal">Open Modal</button>

<!-- Modal -->
<div id="myModal" class="modal fade" role="dialog">
  <div class="modal-dialog">

    <!-- Modal content-->
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal">&times;</button>
        <h4 class="modal-title">Modal Header</h4>
      </div>
      <div class="modal-body">
        <p>Some text in the modal.</p>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
      </div>
    </div>

  </div>
</div>

根据我的理解 data-dismiss =modal属性应该关闭模式,如果你点击它,但我不明白它在幕后的工作原理。我查看了官方文档: http://getbootstrap.com/javascript/#modals-examples但是没有解释。

As per my understanding data-dismiss="modal" attribute should close the modal if you click on it, but i don't understand how it works behind the scene. I checked the official documentation at: http://getbootstrap.com/javascript/#modals-examples but there's no explaination.

推荐答案

隐藏功能在 modal.js 以这种方式。

The hiding functionality is implemented in the modal.js in this way.

this.$element.on('click.dismiss.bs.modal', '[data-dismiss="modal"]', $.proxy(this.hide, this))

基本上它只是找到具有 data-dismiss 属性的元素以及 modal 的值。点击它会隐藏这些元素。

Basically it's just finding the elements that have the attribute of data-dismiss and the value of modal. Upon click it will hide these elements.

这篇关于了解data-dismiss属性在Bootstrap中的工作原理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆