【问题标题】:Jquery confirmation not workingJquery确认不起作用
【发布时间】:2016-06-16 12:25:28
【问题描述】:

我试过这个:https://stackoverflow.com/a/12617274/4164311。字符串“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>

截图:

【问题讨论】:

  • 你真的要使用Jquery的对话吗? javascript基本的确认框还不够吗?
  • @kyori:是的。我无法使用确认框,因为浏览器会阻止打开其他对话框(例如 Chrome)。

标签: jquery jquery-ui confirm confirmation


【解决方案1】:

注意:你需要把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 () { 

        } }

        });


        });

【讨论】:

    【解决方案2】:

    尝试将您的 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");
      });
    });
    

    希望这会有所帮助。

    编辑:另外,添加/更改 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>
    

    【讨论】:

    • 检查这个jsfiddle link。它正在工作。
    • 现在可以了。我的 jquery 和 css 与你的不同。谢谢。
    • 另外,我将我的包含更改为使其工作:&lt;link rel="stylesheet" href="https://code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css"&gt; &lt;script src="https://code.jquery.com/jquery-1.11.3.min.js"&gt;&lt;/script&gt; &lt;script src="https://code.jquery.com/ui/1.11.4/jquery-ui.js"&gt;&lt;/script&gt;
    猜你喜欢
    • 1970-01-01
    • 2014-02-14
    • 2014-02-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-10
    • 1970-01-01
    相关资源
    最近更新 更多