jQuery确认不起作用 [英] Jquery confirmation not working

查看:147
本文介绍了jQuery确认不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试了此操作: https://stackoverflow.com/a/12617274/4164311 .字符串您确定吗"仅出现在我的浏览器中,当我单击按钮时什么也没有发生.

I tried this: https://stackoverflow.com/a/12617274/4164311. The string "Are you sure about this" just appears in my browser and nothing happens when I click the button.

<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代码放入文档就绪函数中,它应该可以工作.

Try placing your js codes inside document ready function and it should work.

$(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包括:

Also, add/change jquery and css includes to:

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

这篇关于jQuery确认不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆