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

Is there a way i can use a jQuery UI based modal dialog for confirmation instead of the normal JS confi

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/

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745675321a4639652.html

相关推荐

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

    Is there a way i can use a jQuery UI based modal dialog for confirmation instead of the normal JS confi

    6小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信