• <tfoot id='HM6wQ'></tfoot>

      <small id='HM6wQ'></small><noframes id='HM6wQ'>

      <i id='HM6wQ'><tr id='HM6wQ'><dt id='HM6wQ'><q id='HM6wQ'><span id='HM6wQ'><b id='HM6wQ'><form id='HM6wQ'><ins id='HM6wQ'></ins><ul id='HM6wQ'></ul><sub id='HM6wQ'></sub></form><legend id='HM6wQ'></legend><bdo id='HM6wQ'><pre id='HM6wQ'><center id='HM6wQ'></center></pre></bdo></b><th id='HM6wQ'></th></span></q></dt></tr></i><div id='HM6wQ'><tfoot id='HM6wQ'></tfoot><dl id='HM6wQ'><fieldset id='HM6wQ'></fieldset></dl></div>
        • <bdo id='HM6wQ'></bdo><ul id='HM6wQ'></ul>

      1. <legend id='HM6wQ'><style id='HM6wQ'><dir id='HM6wQ'><q id='HM6wQ'></q></dir></style></legend>
      2. Twitter Bootstrap/jQuery - 如何暂时防止模式被关闭?

        时间:2023-06-13

          <small id='fGUr2'></small><noframes id='fGUr2'>

              <bdo id='fGUr2'></bdo><ul id='fGUr2'></ul>

                <tfoot id='fGUr2'></tfoot>
                <i id='fGUr2'><tr id='fGUr2'><dt id='fGUr2'><q id='fGUr2'><span id='fGUr2'><b id='fGUr2'><form id='fGUr2'><ins id='fGUr2'></ins><ul id='fGUr2'></ul><sub id='fGUr2'></sub></form><legend id='fGUr2'></legend><bdo id='fGUr2'><pre id='fGUr2'><center id='fGUr2'></center></pre></bdo></b><th id='fGUr2'></th></span></q></dt></tr></i><div id='fGUr2'><tfoot id='fGUr2'></tfoot><dl id='fGUr2'><fieldset id='fGUr2'></fieldset></dl></div>
                • <legend id='fGUr2'><style id='fGUr2'><dir id='fGUr2'><q id='fGUr2'></q></dir></style></legend>

                    <tbody id='fGUr2'></tbody>

                • 本文介绍了Twitter Bootstrap/jQuery - 如何暂时防止模式被关闭?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在使用 Twitter Bootstrap 模态,默认选项是您可以单击背景或按 [Esc] 关闭模态.

                  I am using Twitter Bootstrap modals, with the default options where you can click the backdrop or press [Esc] to close the modal.

                  但是,当我在模式中启动 ajax 操作时,我想禁止模式以任何方式关闭.所以我禁用按钮并隐藏模式的关闭按钮,但我不知道如何禁用背景和 [Esc] 键.

                  However, when I initiate an ajax operation in the modal I want to disable the modal from being closed in any way. So I disable buttons and hide the modal's close button but I can't figure out how to disable the backdrop and the [Esc] key.

                  我试过了:

                  $('#myModal').modal({
                      backdrop: 'static',
                      keyboard: false
                  });
                  

                  但这似乎不能即时工作.

                  But this doesn't seem to work on the fly.

                  ajax 操作完成后,我还需要重新启用背景和键盘.

                  I will also need to re-enable the backdrop and keyboard once the ajax operation is finished.

                  推荐答案

                  注意:此解决方案针对twitter bootstrap 2.x!请参阅 this answer(就在下方)了解根据引导程序 3 的差异.

                  Note: This solution is targeting twitter bootstrap 2.x! See this answer (just below) for differences according to bootstrap 3.

                  扩展引导模式功能而不修改原始源.

                  Extending bootstrap modal functionality without modifying original source.

                  感谢@David 和他在 如何扩展 Twitter Bootstrap 的建议插件 我终于让它工作了.这是他的解决方案的略微修改版本,添加了模态锁定".我将其作为附加答案发布,因为我认为这可能是其他像我一样在这个问题上苦苦挣扎的人的起点.

                  Thanks to @David and his suggestion at How to Extend Twitter Bootstrap Plugin I finally got it to work. It is a slightly modified version of his solution with modal "lock" added. I post it as a additional answer since I think it may could be a starting point for others that like me have struggled hard with this issue.

                  // save the original function object
                  var _superModal = $.fn.modal;
                  
                  // add locked as a new option
                  $.extend( _superModal.defaults, {
                      locked: false
                  });
                  
                  // create a new constructor
                  var Modal = function(element, options) {
                      _superModal.Constructor.apply( this, arguments )
                  }
                  
                  // extend prototype and add a super function
                  Modal.prototype = $.extend({}, _superModal.Constructor.prototype, {
                      constructor: Modal
                  
                      , _super: function() {
                          var args = $.makeArray(arguments)
                          // call bootstrap core
                          _superModal.Constructor.prototype[args.shift()].apply(this, args)
                      }
                  
                      , lock : function() {
                          this.options.locked = true
                      }
                  
                      , unlock : function() {
                          this.options.locked = false
                      }
                  
                      , hide: function() {
                          if (this.options.locked) return
                          this._super('hide')
                      }
                  });
                  
                  // override the old initialization with the new constructor
                  $.fn.modal = $.extend(function(option) {
                      var args = $.makeArray(arguments),
                      option = args.shift()
                  
                      // this is executed everytime element.modal() is called
                      return this.each(function() {
                          var $this = $(this)
                          var data = $this.data('modal'),
                              options = $.extend({}, _superModal.defaults, $this.data(), typeof option == 'object' && option)
                  
                          if (!data) {
                              $this.data('modal', (data = new Modal(this, options)))
                          }
                          if (typeof option == 'string') {
                              data[option].apply( data, args )
                          }
                      });
                  }, $.fn.modal);
                  

                  使用这种技术,无需更改 bootstrap.js,并且可以更轻松地在 bootstrap 项目之间共享相同的功能.此方法应适用于所有其他引导插件.到目前为止只尝试过按钮,但我不知道为什么不应该这样做.

                  With this technique it should not be nessecary to alter bootstrap.js, and the same functionality can more easily be shared among bootstrap projects. This method should be applicable to all the other bootstrap plugins. Have so far only tried with button though, but I cant se why it shouldnt.

                  查看工作小提琴 -> http://jsfiddle.net/Sz7ZS/强>

                  see working fiddle -> http://jsfiddle.net/Sz7ZS/

                  这篇关于Twitter Bootstrap/jQuery - 如何暂时防止模式被关闭?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  <i id='8Ir5O'><tr id='8Ir5O'><dt id='8Ir5O'><q id='8Ir5O'><span id='8Ir5O'><b id='8Ir5O'><form id='8Ir5O'><ins id='8Ir5O'></ins><ul id='8Ir5O'></ul><sub id='8Ir5O'></sub></form><legend id='8Ir5O'></legend><bdo id='8Ir5O'><pre id='8Ir5O'><center id='8Ir5O'></center></pre></bdo></b><th id='8Ir5O'></th></span></q></dt></tr></i><div id='8Ir5O'><tfoot id='8Ir5O'></tfoot><dl id='8Ir5O'><fieldset id='8Ir5O'></fieldset></dl></div>

                  <small id='8Ir5O'></small><noframes id='8Ir5O'>

                  <tfoot id='8Ir5O'></tfoot>
                        <bdo id='8Ir5O'></bdo><ul id='8Ir5O'></ul>
                            <tbody id='8Ir5O'></tbody>
                        1. <legend id='8Ir5O'><style id='8Ir5O'><dir id='8Ir5O'><q id='8Ir5O'></q></dir></style></legend>