1

我试图得到最好的确认为什么 jquery 不工作出了什么问题我没有得到确认对话框

小提琴: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

4 回答 4

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>
于 2017-02-15T05:40:16.140 回答
0
于 2017-02-14T12:33:12.200 回答
0

您可能还有其他问题(如前所述,您似乎没有加载 jQuery,jQuery.confirm依赖于它,这应该会在 JavaScript 控制台中触发一个非常清晰的错误消息),但主要问题是您从不链接您的带有插件的按钮:

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

直接从项目页面:

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

In other words, you need to call the plugin on an jQuery object with a proper selection.

于 2017-02-14T12:37:36.340 回答
0

您缺少 jQuery 库。

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

它必须是 Head Section 下的第一个库。

于 2017-02-14T12:11:52.283 回答