Вопрос

The prompt popup that occurs when I click the button with class 'alert3' does not close.

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

and this is the function that I am invoking:

<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>
Это было полезно?

Решение

The popup does not close because you have an error in the callback function, so it crashes before bootbox can make the popup disappear.

The best guess is that Example is not defined in your code. Maybe you took it on the Bootbox website, they are using a javascript object called Example. If you want to show the result with your callback function, you can add this to your html:

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

And then change your 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>

Другие советы

Prompt popup in bootbox.js

That is not working because Example function is not defined there.We need to first defined them that using current selector value and text associated with them.here $("#result") is used to show error message in particular div.

html code:

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

code:

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;
}());
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top