【问题标题】:Need help to implement CloseOnEscape Key Press for JQModal with IFrame需要帮助使用 IFrame 为 JQModal 实现 CloseOnEscape Key Press
【发布时间】:2012-02-26 12:59:58
【问题描述】:

我在我的项目中使用 JqModal。它是一个不错的 JS 模态。但是,我需要一个帮助才能将 Close On Escape 按键附加到 JqModal。我正在从 JqModal 中的外部 URL 加载永恒的内容。

对于没有使用 IFrame 的简单 Modal,很容易实现 CloseOnEscape 按键功能。

【问题讨论】:

    标签: javascript jqmodal


    【解决方案1】:

    我通过更新 jqModal.js 文件使其工作

    步骤:

    1. 将选项“closeOnEsc: true”添加到 jqModal。所以选项看起来像这样,

          var p = {
          overlay: 50,
          overlayClass: 'jqmOverlay',
          closeClass: 'jqmClose',
          trigger: '.jqModal',
          ajax: F,
          ajaxText: '',
          target: F,
          modal: F,
          toTop: F,
          onShow: F,
          onHide: F,
          onLoad: F,
          closeOnEsc: true
      };
      
    2. 在 jqModal 打开函数中添加以下代码。

          var modal = $(h.w);
      
          modal.unbind("keydown");
      
          if (c.closeOnEsc) {
              modal.attr("tabindex", 0);
              modal.bind("keydown", function (event) {
                  if (event.keyCode == 27) {
                      event.preventDefault();                        
                      modal.jqmHide();
                  }
              });
              modal.focus();
          }
      

    【讨论】:

      【解决方案2】:

      来自http://forum.jquery.com/topic/jquery-jqmodal-and-the-esc-key

      document.onkeydown = function(e){
          if (e == null) { // ie
             keycode = event.keyCode;
          } else { // mozilla
             keycode = e.which;
          }
          if(keycode == 27){ // escape, close box
             $('.jqmWindow').jqmHide();
           }
      };
      

      其中 '.jqmQWindow' 是您将 jqModal 附加到的窗口或容器。

      【讨论】:

        【解决方案3】:

        我更新了 user1233802 对 jqModal 最新版本的回答(截至 2014 年 2 月 21 日):

        http://pastebin.com/7RQG1Jj3

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2021-03-30
          • 1970-01-01
          • 1970-01-01
          • 2022-07-12
          • 1970-01-01
          • 1970-01-01
          • 2013-11-19
          相关资源
          最近更新 更多