最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

javascript - Using jQuery UI modal dialog as confirm - Stack Overflow

matteradmin7PV0评论

Is there a way i can use a jQuery UI based modal dialog for confirmation instead of the normal JS confirm()? I would like to be able to do something like:

if (jquery_ui_confirm('Are you sure?')) {
    // do something
}

Thanks in advance.

Is there a way i can use a jQuery UI based modal dialog for confirmation instead of the normal JS confirm()? I would like to be able to do something like:

if (jquery_ui_confirm('Are you sure?')) {
    // do something
}

Thanks in advance.

Share Improve this question asked May 24, 2013 at 10:25 Gonçalo MarrafaGonçalo Marrafa 2,1134 gold badges29 silver badges35 bronze badges 3
  • It's a bit more plicated because you need to provide the HTML for the dialog box and handle the result as callbacks, but yeah there's no reason this can't work. Have you tried it? – Rup Commented May 24, 2013 at 10:26
  • 2 ... Its part of the basic docs; jqueryui./dialog/#modal-confirmation – Alex K. Commented May 24, 2013 at 10:27
  • you can also use Jquery Alert plugin as well. – Muhammad Sannan Khalid Commented May 24, 2013 at 10:34
Add a ment  | 

3 Answers 3

Reset to default 4
var jqConfirm = function(msg, success) {
    var dialogObj = $("<div style='display:none'>"+msg+"</div>");
    $("body").append(dialogObj);
    $(dialogObj).dialog({
      resizable: false,
      height:140,
      modal: true,
      buttons: {
        "OK": function() {
         success();
          $( this ).dialog( "close" );
        },
        Cancel: function() {
          $( this ).dialog( "close" );
        }
      }
    });
  };

Call this function using

jqConfirm("This will delete all records", function(){ /*do something here */});

yes you can.. you can provide requried html to dialog

<script>
$(function() {
    $( "#dialog-confirm" ).dialog({
        resizable: false,
        height:140,
        modal: true,
        buttons: {
            "OK": function() {
                $( this ).dialog( "close" );
                },
                Cancel: function() {
                    $( this ).dialog( "close" );
                }
        }
    });
});
</script>

HTML Code

<div id="dialog-confirm" title="Confirmation Dialog">
    <p>
        <span class="ui-icon ui-icon-alert"
            style="float: left; margin: 0 7px 20px 0;"></span>Would you like to delete this item?
    </p>
</div>

you can also use Jquery Alert plugin as well. Here is a link: http://labs.abeautifulsite/archived/jquery-alerts/demo/

Post a comment

comment list (0)

  1. No comments so far