jQuery Mobile Popup afteropen事件

jQuery Mobile Popup afteropen事件

jQuery Mobile是一个JavaScript库,用于为手机、标签和台式机等各种屏幕尺寸的设备创建可访问和响应的内容。在这篇文章中,我们将使用jQuery Mobile Popup afteropen 事件,该事件在弹出窗口完全打开后被触发。

回调参数:回调函数接受一个事件类型的event参数和一个 UI对象。这里的UI对象是空的,包括它只是为了与整个jQuery Mobile库的其他事件保持一致。

语法:

  • 用指定的afteropen回调初始化弹出窗口。
$(".selector").popup({
    afteropen: function (event, ui) {
        // Your code here
    }
});
  • 将popupafteropen事件绑定到一个事件监听器上。
$(".selector").on("popupafteropen", function (event, ui) { });

CDN 链接:

<link rel=”stylesheet” href=”https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css” />
<script src=”https://code.jquery.com/jquery-2.1.3.js”></script>
<script src=”https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.js”></script>

例子:在下面的例子中,当afteropen甚至触发时,我们将id为”write”的段落的文本设置为”afteropen Event triggered”

<!DOCTYPE html>
<html lang="en">
  
<head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" 
          content="width=device-width, initial-scale=1.0" />
    <title>Popup - afteropen Event</title>
  
    <link rel="stylesheet"
          href=
"https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css" />
    <script src=
"https://code.jquery.com/jquery-2.1.3.js"></script>
    <script src=
"https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.js">
    </script>
  
    <script>
        (document).ready(function () {
            ("#popup1").popup({
                afteropen: function (event, ui) {
                    ("#write").text("afteropen Event triggered");
                }
            });
        });
  
        function openPopup() {
            ("#popup1").popup("open", { positionTo: "#target" });
        }
    </script>
</head>
  
<body>
    <div data-role="page">
        <center>
            <h2 style="color: green">GeeksforGeeks</h2>
            <h3>jQuery Mobile Popup afteropen Event</h3>
  
            <p id="target">Popup will open here</p>
  
            <div data-role="popup" id="popup1">
                <p>Welcome to GeeksforGeeks</p>
            </div>
  
            <button style="width: 450px;" 
                    onclick="openPopup()">Open Popup</button>
  
            <p style="background-color: green; color: white;" 
               id="write"></p>
        </center>
    </div>
</body>
  
</html>

输出:

jQuery Mobile Popup afteropen事件

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程