簡體   English   中英

JavaScript確認更改為jquery模式對話框

[英]Javascript Confirm change into jquery modal dialog

我這里有一個通過ajax刪除的記錄。 如果要刪除記錄,則添加確認消息。 我需要將確認消息更改為模式對話框http://jqueryui.com/dialog/#modal-confirmation

我想更改此javascript代碼

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

進入這個jQuery模式對話框。 有什么幫助嗎?

<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刪除

<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>

您將在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");
};

然后使用它,但請注意不要在其上使用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