为什么jquery确认无法正常工作

时间:2017-02-14 12:08:37

标签: jquery jquery-confirm

我正在努力获得最好的确认,为什么jquery无法正常运行出错了我没有得到确认dailog box

小提琴:https://jsfiddle.net/trso8x65/

<html>
     <head>
     <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
      <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jquery-confirm/3.0.3/jquery-confirm.min.css">
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-confirm/3.0.3/jquery-confirm.min.js"></script>
     </head>
     <body>

      <button type="button" class="confirm">click me </button>
    <script>
      $.confirm({
        title: 'Confirm!',
        content: 'Simple confirm!',
        buttons: {
            confirm: function () {
                $.alert('Confirmed!');
            },
            cancel: function () {
                $.alert('Canceled!');
            },
            somethingElse: {
                text: 'Something else',
                btnClass: 'btn-primary',
                keys: ['enter', 'shift'],
                action: function(){
                    $.alert('Something else?');
                }
            }
        }
    });
    </script>
     </body>
    </html>

4 个答案:

答案 0 :(得分:1)

这就是它应该如何工作

 <html>
 <head>
   <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
   <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
   <link href="https://cdnjs.cloudflare.com/ajax/libs/jquery-confirm/3.0.3/jquery-confirm.min.css" rel="stylesheet">
   <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-confirm/3.0.3/jquery-confirm.min.js"></script>
 </head>
 <body>
  <button class="btn btn-primary" id="complexConfirm">Click me</button>


   <script>


   $("#complexConfirm").confirm({
    title: 'Confirm!',
    content: 'Simple confirm!',
    buttons: {
        confirm: function () {
            $.alert('Confirmed!');
        },
        cancel: function () {
            $.alert('Canceled!');
        },

    }
});

   </script>
 </body>
</html>

答案 1 :(得分:0)

你缺少jQuery库。

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>

它必须是头部下的第一个图书馆。

答案 2 :(得分:0)

答案 3 :(得分:0)

您可能还有其他问题(如上所述,您似乎没有加载jQuery.confirm所依赖的jQuery,这应该会在JavaScript控制台中触发非常明确的错误消息)但是主要的问题是你永远不会将你的按钮与插件链接:

<button type="button" class="confirm">click me </button>
$.confirm();

从项目页面开始:

<a href="home" class="confirm">Go to home</a>
$(".confirm").confirm();

换句话说,您需要使用正确的选择在jQuery对象上调用插件。

相关问题