문제

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