【问题标题】:Prompt popup in bootbox is not closing引导箱中的提示弹出窗口未关闭
【发布时间】:2013-11-02 21:07:49
【问题描述】:

单击“alert3”类按钮时弹出的提示没有关闭。

<a href="#" class="btn btn-primary btn-lg alert3">CLICKMEMEMEMEMEME</a>

这是我正在调用的函数:

<script>

    $(document).on("click", ".alert3", function(e) {
        bootbox.prompt("What is your name?", function(result) {                
            if (result === null) {                                             
                Example.show("Prompt dismissed");                              
            } else {
            Example.show("Hi <b>"+result+"</b>");                          
            }
        });
    });
</script>

【问题讨论】:

    标签: javascript jquery html bootbox


    【解决方案1】:

    弹窗没有关闭是因为你的回调函数有错误,所以在bootbox使弹窗消失之前就崩溃了。

    最好的猜测是您的代码中没有定义Example。也许你是在 Bootbox 网站上看到的,他们使用了一个名为 Example 的 javascript 对象。 如果你想用你的回调函数显示结果,你可以把它添加到你的 html 中:

    <a href="#" class="btn btn-primary btn-lg alert3">CLICKMEMEMEMEMEME</a><br/>
    <p id='result'></p>
    

    然后更改您的javascript:

    <script>
    $(document).on("click", ".alert3", function(e) {
        bootbox.prompt("What is your name?", function(result) {
            if (result === null) {
                $('#result').html("Prompt dismissed");
            } else {
                $('#result').html("Hi <b>"+result+"</b>");
            }
        });
    });
    </script>
    

    【讨论】:

      【解决方案2】:

      bootbox.js 中的提示弹窗

      这不起作用,因为那里没有定义示例函数。我们需要首先使用当前选择器值和与它们关联的文本来定义它们。这里 $("#result") 用于在特定的 div 中显示错误消息。

      html代码:

        <p>Click here-><a class="alert" href=#>Alert!</a></p><p id='result'</p>
      

      代码:

      var Example = (
      function() 
      {
      "use strict";
      
      var elem,
          hideHandler,
          that = {};
      
      that.init = function(options) {
          elem = $(options.selector);
      };
      that.show = function(text) {
          clearTimeout(hideHandler);
      
          $("#result").html(text);
          $("#result").fadeIn();
      
          hideHandler = setTimeout(function() {
              that.hide();
          }, 4000);
      };
      
      that.hide = function() {
          $("#result").fadeOut();
      };
      
      return that;
      }());
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-01-06
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-02-16
        • 1970-01-01
        • 2013-05-22
        • 1970-01-01
        相关资源
        最近更新 更多