简体   繁体   中英

Show hidden bootboxjs dialog

I create a modal dialog via bootboxjs , with option show: false

  bootbox.dialog({
    message: "Whatever",
    show: false,
  });

How can I then show that dialog (eg on a click event)?

Thanks!

I haven't used Bootbox before, but after looking at the source, you add the data-bb="dialog" attribute onto the button. Then, define a click function at the top of your script:

Note: I am using demo namespace. I saw it in the source they were using on the page. So change this

$(function() {
    var demos = {}; // object namespace

    $(document).on("click", "a[data-bb]", function(e) { // all buttons that have this attribute
        e.preventDefault();
        var type = $(this).data("bb"); // get what type it is (alert, dialog, etc.)

        if (typeof demos[type] === 'function') {
            demos[type](); // run that type (demos.alert(), demos.dialog(), etc.)
        }
    });

    demos.dialog = function() {
       bootbox.dialog({
          message: "Whatever"
       });
    };
});

Hope this helps in some way

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM