简体   繁体   English

JavaScript确认更改为jquery模式对话框

[英]Javascript Confirm change into jquery modal dialog

I have here a delete record via ajax. 我这里有一个通过ajax删除的记录。 I add confirm message if I want to delete the record or not. 如果要删除记录,则添加确认消息。 What I need is change the confirm message into modal dialog http://jqueryui.com/dialog/#modal-confirmation . 我需要将确认消息更改为模式对话框http://jqueryui.com/dialog/#modal-confirmation

I want to change this javascript code 我想更改此javascript代码

if(confirm("All PR and PO in this record will be deleted. Are you want to delete?"))

into this jquery modal dialog. 进入这个jQuery模式对话框。 Any help? 有什么帮助吗?

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

Ajax delete Ajax删除

<script>
$(function () {
  $(".delbutton").click(function () {
    //Save the link in a variable called element
    var element = $(this);
    //Find the id of the link that was clicked
    var del_id = element.attr("name");
    //Built a url to send
    var info = 'name=' + del_id;
    if (confirm("All PR and PO in this record will be deleted. Are you want to delete?")) {
      $.ajax({
        type: "GET",
        url: "delete.php",
        data: info,
        success: function () {}
      });
      $(this).parents(".record").animate({
        backgroundColor: "#fbc7c7"
      }, "fast")
        .animate({
          opacity: "hide"
        }, "slow");
    }
    return false;
  });
});
</script>

You will override confirm method of javascript in your html code as follow 您将在HTML代码中覆盖JavaScript的确认方法,如下所示

 <script>
 function confirm(message) {
 var myTitle = 
        "<div style='float: left'>Error</div><div style='float: right; margin-right: 15px;'>Close</div>";
        $('<div id="dlgTest1" style="display: none;min-height:auto;"><p style="text-align:justify;font-family:verdana;font-weight: bold;">'+message+'</p></div>').dialog({
resizable: false,
        modal: true,
        width: 300,
        height: 'auto',
        bgiframe: false,
        //position: ['top', 5],
        draggable: true,
        closeOnEscape: true,
        minHeight:20,
        buttons: [{
            text: "Cancel",
            "style": 'background-color:#CCCCCC !important;color:rgb(119, 119, 119);font-family:verdana',
              click:function(){
                $(this).dialog('close');
                return false;
            }

        },{
        text: "Ok",
        "style": 'background-color:#007AC0 !important;color:white;font-family:verdana',
          click:function(){
            $(this).dialog('close');
        }
        }
        ],
        close:function(){ $(this).dialog('destroy').remove(); }
    }).siblings('.ui-dialog-titlebar').append(myTitle); // title goes here;
    //$("#dlgTest1").dialog("open").dialog("moveToTop");
};

and then use it , But be careful don't use html submit button on it, Use html normal button 然后使用它,但请注意不要在其上使用html提交按钮,请使用html普通按钮

 //try this code   

 <script>
    var isConfirmed=false;
    $(function () {
      $("#dialog-confirm").dialog({
        resizable: false,
        height: 140,
        modal: true,
        buttons: {
          "Delete all items": function () {
             isConfirmed=true;
            $(this).dialog("close");
          },
          Cancel: function () {
            isConfirmed=false;
            $(this).dialog("close");
          }
        }
      });


    $(".delbutton").click(function () {
        //Save the link in a variable called element
        var element = $(this);
        //Find the id of the link that was clicked
        var del_id = element.attr("name");
        //Built a url to send
        var info = 'name=' + del_id;
        $("#dialog-confirm").html("All PR and PO in this record will be deleted. Are you want to delete?");
        if (isConfirmed) {
          $.ajax({
            type: "GET",
            url: "delete.php",
            data: info,
            success: function () {}
          });
          $(this).parents(".record").animate({
            backgroundColor: "#fbc7c7"
          }, "fast")
            .animate({
              opacity: "hide"
            }, "slow");
        }
        return false;
      });
    });
    </script>
//replace your script with this code and try

 <script>
    var isConfirmed=false;
    $(function () {
      $("#dialog-confirm").dialog({
        resizable: false,
        height: 140,
        modal: true,
        buttons: {
          "Delete all items": function () {
             isConfirmed=true;
            $(this).dialog("close");
          },
          Cancel: function () {
            isConfirmed=false;
            $(this).dialog("close");
          }
        }
      });


    $(".delbutton").click(function () {
        //Save the link in a variable called element
        var element = $(this);
        //Find the id of the link that was clicked
        var del_id = element.attr("name");
        //Built a url to send
        var info = 'name=' + del_id;
        $("#dialog-confirm").html("All PR and PO in this record will be deleted. Are you want to delete?");
$("#dialog-confirm").dialog();
        if (isConfirmed) {
          $.ajax({
            type: "GET",
            url: "delete.php",
            data: info,
            success: function () {}
          });
          $(this).parents(".record").animate({
            backgroundColor: "#fbc7c7"
          }, "fast")
            .animate({
              opacity: "hide"
            }, "slow");
        }
        return false;
      });
    });
    </script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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