jQuery Mobile - 多頁模板



描述

可以在單一的 jQuery Mobile 文件中,新增多個帶有屬性 data-role = "page" 的 div,將其合併在一起載入多個頁面。帶有 data-role = "page" 的 div 應包括唯一的 ID,以便在頁面間進行內部連結。

示例

以下示例演示如何在 jQuery Mobile 中使用多頁。

<!DOCTYPE html>
<html>
   <head>
      <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-1.11.3.min.js"></script>
      <script src = "https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
   </head>
   
   <body>
      <div data-role = "page" id = "page1">
         <div data-role = "header">
            <h2>Header</h2>
         </div>
         
         <div role = "main" class = "ui-content">
            <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p>
            <p> For more information <a href = "#page2">click here</a></p>
         </div>
         
         <div data-role = "footer">
            <h4>Footer</h4>
         </div>
      </div>
      
      <div data-role = "page" id = "page2">
         <div data-role = "header">
            <h1>Header Text</h1>
         </div>
         
         <div role = "main" class = "ui-content">
            <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. 
            Lorem Ipsum has been the  industry's standard dummy text ever since the 
            1500s.</p>
            
            <p><a href = "#page1">Back to previous page</a></p>
         </div>
         
         <div data-role = "footer">
            <h4>Footer Text</h4>
         </div>
      </div>
   </body>
</html>

輸出

讓我們執行以下步驟,看看上面的程式碼如何工作 −

  • 將上面的 html 程式碼另存為 multiple_page.html 檔案放到伺服器根資料夾中。

  • 以 https:///multiple_page.html 方式開啟此 HTML 檔案,將顯示以下輸出。

jquery_mobile_pages.htm
廣告
© . All rights reserved.