jQuery Mobile panel beforeclose事件

jQuery Mobile panel beforeclose事件

jQuery Mobile是一套基于HTML5的用户界面系统,是建立在jQuery之上的。它用于为各种设备如手机、平板电脑、笔记本电脑和台式机创建响应式和可访问的网站和网络应用。

在这篇文章中,我们将使用jQuery Mobile的panel beforeclose事件,当关闭面板的过程开始时触发。

语法:

  • 用指定的beforeclose回调初始化面板。
$( ".selector" ).panel({
  beforeclose: function( event, ui ) {
      // Your code here
  }
});
  • 为panelbeforeclose事件绑定一个事件监听器。
$(".selector").on( "panelbeforeclose", function( event, ui ) {} );

参数:它接受一个有两个参数的回调函数。

  • event。它接受事件类型值。
  • ui。它接受对象类型的值。ui对象可以是空的,但为了与整个库的其他事件保持一致。

CDN links:

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

例子:在下面的例子中,当beforeclose事件被触发时,会出现一个警报框。

<!DOCTYPE html>
<html lang="en">
  
<head>
    <meta charset="utf-8">
    <meta name="viewport" content=
          "width=device-width, initial-scale=1">
  
    <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 () {
            
             // Initialize the panel with
              // beforeclose callback specified
            ("#divID").panel({
                beforeclose: function (event, ui) {
                    alert("Panel beforeclose event fired.")
                }
            });
        });
          
          // A function to close the panel.
        function closePanel() {
            $("#divID").panel("close");
        }
    </script>
</head>
  
<body>
    <div data-role="page">
        <div data-role="header">
            <h1 style="color:green;">GeeksforGeeks</h1>
            <h3>jQuery Mobile Panel beforeclose event</h3>
        </div>
  
        <div role="main" class="ui-content">
            <center>
                <a href="#divID">Open Panel</a>
            </center>
        </div>
        <div data-role="panel" id="divID">
            <button onclick="closePanel();">Close Panel</button>
        </div>
    </div>
</body>
</html>

输出:

jQuery Mobile panel beforeclose事件

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程