jQuery Mobile面板close事件

jQuery Mobile面板close事件

jQuery Mobile是一个JavaScript库,用于为手机、标签、桌面等创建响应性和可访问性的网络应用。在这篇文章中,我们将使用jQuery Mobile Panel close事件,该事件是在面板完全关闭后触发的。

语法:

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

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

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

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>

例子:在下面的例子中,当面板close事件被触发时,我们改变了id为 “write “的段落的文本。

<!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 () {
            ("#divID").panel({
                close: function (event, ui) { 
                    ("#write").text("Panel close event fired.")
                }
            });
        });
  
        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 close event</h3>
        </div>
  
        <div role="main" class="ui-content">
            <center>
                <a href="#divID">Open Panel</a>
  
                <p style="background-color:green; 
                          color:white;" id="write">
                </p>
  
            </center>
          </div>>
  
        <div data-role="panel" id="divID">
            <button onclick="closePanel();">
                Close Panel
            </button>
        </div>
    </div>
</body>
</html>

输出:

jQuery Mobile面板关闭事件

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程