Javascript 为什么在下面的代码中,OK按钮没有显示在弹出窗口中?

Javascript 为什么在下面的代码中,OK按钮没有显示在弹出窗口中?,javascript,jquery,jquery-ui,jquery-ui-dialog,alert,Javascript,Jquery,Jquery Ui,Jquery Ui Dialog,Alert,我的代码如下: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <link href="http://localhost/abc/pqr/web/c

我的代码如下:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <link href="http://localhost/abc/pqr/web/css_new/style.css" rel="stylesheet" type="text/css" />
    <link href="http://localhost/abc/pqr/web/css_new/scroll.css" rel="stylesheet" type="text/css" />
    <link rel="stylesheet" href="http://localhost/abc/pqr/web/css/jquery_ui/ui.all.css" type="text/css" />

    <script type="text/javascript" src="http://localhost/abc/pqr/web/js/jquery-1.7.1.min.js"></script>
    <script type="text/javascript" src="http://localhost/abc/pqr/web/js/jquery_ui/ui.core.js"></script> 
    <script type="text/javascript" src="http://localhost/abc/pqr/web/js/jquery_ui/ui.dialog.js"></script>

    <script>
      var timer;
      var keys = {};

      $(document).ready(function () {
        $(document).mouseleave(function () {
          customAlert("Your mouse is away");
        });
      });

      $(document).keydown(function (e) {
        keys[e.which] = true;
      });

      $(document).keyup(function (e) {
        delete keys[e.which];
      });

      if( (keys[91] && keys[68]) || (keys[18] && keys[9]) || (keys[17] && keys[91] && keys[68]) ) { 
        customAlert("Your mouse is away");
      }

      function customAlert(customText) {
        $("#popUp").html(customText);
        timer = setInterval(customAlert2, 5000);

        $("#popUp").dialog({
          dialogClass: "no-close",
          buttons: [{
                      text: "OK", click: function () {
                        $(this).dialog("close");
                        clearInterval(timer);
                      }
                    }]
        });
      }

      function customAlert2() {
        location.reload();
        $("#popUp2").dialog({
        dialogClass: "no-close",
        buttons: [{
                  text: "OK", click: function () {
                    $(this).dialog("close");
                  }
                }]
        });
      }      
    </script>
  </head>
  <body>
    <h1>My first PHP program</h1>
    <p>Hello World!</p>
    <div id="popUp" title="First alert message"></div>
    <div id="popUp2" title="Second alert message">Time is over</div>
  </body>
</html>

无功定时器;
var键={};
$(文档).ready(函数(){
$(文档).mouseleave(函数(){
customAlert(“您的鼠标不在了”);
});
});
$(文档).keydown(函数(e){
键[e.which]=true;
});
$(文档).keyup(函数(e){
删除键[e.which];
});
如果((键[91]&键[68])| |(键[18]&键[9])| |(键[17]&键[91]&键[68]){
customAlert(“您的鼠标不在了”);
}
功能customAlert(customText){
$(“#弹出窗口”).html(自定义文本);
定时器=设置间隔(customAlert2,5000);
$(“#弹出窗口”)。对话框({
dialogClass:“禁止关闭”,
按钮:[{
文本:“确定”,单击:函数(){
$(此).dialog(“关闭”);
清除间隔(计时器);
}
}]
});
}
函数customAlert2(){
location.reload();
$(“#popUp2”)。对话框({
dialogClass:“禁止关闭”,
按钮:[{
文本:“确定”,单击:函数(){
$(此).dialog(“关闭”);
}
}]
});
}      
我的第一个PHP程序
你好,世界

时间已经过去了

当弹出窗口显示时,Ok按钮缺失。它只显示“O”。在这方面你能帮我吗?我还附上了弹出窗口的屏幕截图。请看一下,以便更好地了解我的问题。

jQuery UI文档描述了定义按钮的不同方法

官方文件中的一个示例:

$( "#dialog-confirm" ).dialog({
  resizable: false,
  height:140,
  modal: true,
  buttons: {
    "Delete all items": function() {
      $( this ).dialog( "close" );
    },
    Cancel: function() {
      $( this ).dialog( "close" );
    }
  }
});

因此,在您的情况下,它应该是这样的:

$("#popUp").dialog({
      dialogClass: "no-close",
      buttons: {
          "OK": function () {
              $(this).dialog("close");
              clearInterval(timer);
          }
      }
});

$("#popUp2").dialog({
      dialogClass: "no-close",
      buttons: {
          "OK": function () {
              $(this).dialog("close");
          }
      }
});

我在JS fiddle上尝试了你的代码,并使用你在那里提供的自定义警报调用了mouseleave函数,它工作正常,即当我离开输出窗口时,它会显示带有“OK”按钮的对话框

请找到这个链接,并写下你的第二个外汇太,也许我们可以找到一些在那里

请在下面找到jsFiddle


您的第一个PHP程序中没有PHP!哈哈.)非常感谢你的帮助,玛丽。但我对上面的代码有异议。我不能像以前那样在Ok按钮上触发Click事件。您尚未在“确定”按钮上定义单击事件。如何实现这一点?@PHPLover按钮名称后面的匿名函数是单击后执行的函数。您应该在jsfiddle.net上重新创建您的问题,这样我们就可以测试您的代码并帮助修复它。
$(document).mouseleave(function () {
           //$( "#popUp" ).dialog( "open" );  
          customAlert('Hi');
        });