jQuery UI对话框open()方法

  • Post category:jquery

以下是关于 jQuery UI 对话框 open() 方法的详细攻略:

jQuery UI 对话框 open() 方法

open() 方法用于打开对话框。可以使用该方法在对话框初始化后打开对话框。

语法

$(selector).dialog("open");

参数

无参数。

示例一:使用按钮打开对话框

<!DOCTYPE html>
<html>
<head>
  <title>jQuery UI Dialog open() 方法示例</title>
  <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
  <script src="https://code.jquery.com/ui/1.13.0/jquery-ui.min.js"></script>
  <link rel="stylesheet" href="https://code.jquery.com/ui/1.13.0/themes/base/jquery-ui.css">
</head>
<body>
  <button id="open-dialog">Open Dialog</button>
  <div id="dialog" title="Basic dialog">
    <p>This is an example dialog.</p>
  </div>
  <script>
    $( "#dialog" ).dialog({
      autoOpen: false
    });
    $( "#open-dialog" ).click(function() {
      $( "#dialog" ).dialog( "open" );
    });
  </script>
</body>
</html>

这将创建一个对话框,当用户单击 “Open Dialog” 按钮时打开。

示例二:使用时器打开对话框

<!DOCTYPE html>
<html>
<head>
  <title>jQuery UI Dialog open() 方法示例</title>
  <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
  <script src="https://.jquery.com/ui/1.13.0/jquery-ui.min.js"></script>
  <link rel="stylesheet" href="https://code.jquery.com/ui/1.13.0/themes/base/jquery-ui.css">
</head>
<body>
  <div id="dialog" title="Basic dialog">
    <p>This is an example dialog.</p>
  </div>
  <script>
    $( "#dialog" ).dialog({
      autoOpen: false
    });
    setTimeout(function() {
      $( "#dialog" ).dialog( "open" );
    }, 5000);
  </script>
</body>
</html>

这将创建一个对话框,5秒后自动打开。

总结:

open() 方法用于打开对话框。可以使用该方法在对话框初始化后打开对话框。可以通过按钮或定时器等方式触发该方法。