Jquery 确认无效

Jquery confirmation not working

我试过这个:。字符串 "Are you sure about this" 刚刚出现在我的浏览器中,当我单击该按钮时没有任何反应。

<html lang="en">
<head>
  <meta charset="utf-8">
  <title>jQuery UI Dialog - Modal confirmation</title>

  <link rel="stylesheet" href="jquery-ui.min.css">
  <script src="external/jquery/jquery.js"></script>
  <script src="jquery-ui.min.js"></script>

  <script>
   $("#dialog").dialog({
   autoOpen: false,
   modal: true,
   buttons : {
        "Confirm" : function() {
            alert("You have confirmed!");            
        },
        "Cancel" : function() {
          $(this).dialog("close");
        }
      }
    });

    $("#callConfirm").on("click", function(e) {
      e.preventDefault();
      $("#dialog").dialog("open");
    });
  </script>
</head>
<body>
<button id="callConfirm">Confirm!</button>

<div id="dialog" title="Confirmation Required">
  Are you sure about this?
</div>
</body>
</html>

截图:

尝试将您的 js 代码放入文档就绪函数中,它应该可以工作。

$(function() {
  $("#dialog").dialog({
    autoOpen: false,
    modal: true,
    buttons: {
      "Confirm": function() {
        alert("You have confirmed!");
      },
      "Cancel": function() {
        $(this).dialog("close");
      }
    }
  });

  $("#callConfirm").on("click", function(e) {
    e.preventDefault();
    $("#dialog").dialog("open");
  });
});

希望对您有所帮助。

编辑:此外,add/change jquery 和 css 包括:

 <link rel="stylesheet" href="https://code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
  <script src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
  <script src="https://code.jquery.com/ui/1.11.4/jquery-ui.js"></script>

注意:需要在cdn链​​接下方放

<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/jquery-
       confirm/3.3.2/jquery-confirm.min.css">   
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery- 
       confirm/3.3.2/jquery- confirm.min.js"></script>


 $("#btnSubmit").click(function(){

     $.confirm({

     title: 'Confirmation !!',

      content: 'Are you sure, delete this item?',

       buttons: {

        confirm: function () {
         // write your logic    
                 },      
         cancel: function () { 

        } }

        });


        });