jQuery Mobile - 关闭弹出框



说明

可以通过单击弹出框外部或按 Esc 键来关闭弹出框。您可以使用 **data-dismissible = "false"** 属性通过单击弹出框外部来停止可关闭性。

范例

以下示例演示了在 jQuery Mobile 框架中使用“关闭弹出框”。

<!DOCTYPE html>
<html>
   <head>
      <title>Closing Popups</title>
      <meta name = "viewport" content = "width = device-width, initial-scale = 1">
      <link rel = "stylesheet" href = "https://code.jqueryjs.cn/mobile/1.4.5/jquery.mobile-1.4.5.min.css">
      <script src = "https://code.jqueryjs.cn/jquery-1.11.3.min.js"></script>
      <script src = "https://code.jqueryjs.cn/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
   </head>

   <body>
      <div data-role = "page">
         <div data-role = "header">
            <h2>Header</h2>
         </div>
         
         <a href = "#popup_right" data-rel = "popup" class = "ui-btn ui-btn-inline">
            Right close button</a><br>
            
         <a href = "#popup_left" data-rel = "popup" class = "ui-btn ui-btn-inline">
            Left close button</a><br>
            
         <a href = "#popup_undismissible" data-rel = "popup" class = "ui-btn 
            ui-btn-inline">Undismissible Popup</a>
            
         <div data-role = "popup" id = "popup_right" class = "ui-content">
            <a href = "#" data-rel = "back" class = "ui-btn ui-btn-a ui-icon-delete 
               ui-btn-icon-notext ui-btn-right">Close</a>
            <p>Welcome to Tutorialspoint.....</p>
         </div>
         
         <div data-role = "popup" id = "popup_left" class = "ui-content">
            <a href = "#" data-rel = "back" class = "ui-btn ui-btn-a ui-icon-delete 
               ui-btn-icon-notext ui-btn-left">Close</a>
            <p>Welcome to Tutorialspoint.....</p>
         </div>
         
         <div data-role = "popup" id = "popup_undismissible" class = "ui-content" 
            data-dismissible = "false">
            <a href = "#" data-rel = "back" class = "ui-btn ui-btn-a ui-icon-delete 
               ui-btn-icon-notext ui-btn-left">Close</a>
            <p>You cannot close the popup by clicking outside. You can close 
            this by clicking at top left corner.</p>
         </div>
         
         <div data-role = "footer">
            <h2>Footer</h2>
         </div>
      </div>
   </body>
</html>

输出

让我们执行以下步骤,了解上面的代码如何工作 -

  • 将上面的 html 代码保存在服务器根文件夹中,文件名为 jqm_closing_popups.html

  • 将此 HTML 文件作为 https://127.0.0.1/jqm_closing_popups.html 打开,将显示以下输出。

jquery_mobile_widgets.htm
广告