3

下面是布局在一页上的 jQuery 页面结构。jQuery mobile 将每个 data-role='page' 视为用户可以浏览的不同页面。

我的项目现在变得相当大,我在同一个 .php 文件上有 10 个 data-role='page' 页面,我想将它们分成 10 个页面,但仍然保留 jQuery Mobile 提供的功能。我怎样才能做到这一点?

<body> 
<!-- Start of first page -->
<div data-role="page" id="foo">

<div data-role="header">
    <h1>Foo</h1>
</div><!-- /header -->

<div data-role="content">   
    <p>I'm first in the source order so I'm shown as the page.</p>      
    <p>View internal page called <a href="#bar">bar</a></p> 
</div>

<div data-role="footer">
    <h4>Page Footer</h4>
</div>
</div><!-- /page -->

<!-- Start of second page -->
<div data-role="page" id="bar">

<div data-role="header">
    <h1>Bar</h1>
</div>

<div data-role="content">       
</div>

<div data-role="footer">
    <h4>Page Footer</h4>
</div>
</div><!-- /page -->
</body>
4

3 回答 3

7

jQuery mobile 有两个页面模板。

一个人将每个页面都放在一个 HTML 文件中,就像您的情况一样。它也被称为多页模板。

第二个每 1 个 HTML 文件有 1 页。它被称为多HTML模板。

在此处阅读有关它们的更多信息。

您需要的是一个多 HTML 模板。这是一个工作示例:

HTML 1 - index.html:

<!DOCTYPE html>
  <html>
    <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="widdiv=device-widdiv, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
    <meta name="apple-mobile-web-app-capable" content="yes" />
    <meta name="apple-mobile-web-app-status-bar-style" content="black" />
    <title>
    </title>
    <link rel="stylesheet" href="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.css" />
    <script src="http://www.dragan-gaic.info/js/jquery-1.8.2.min.js">
    </script>
    <script src="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.js"></script>  
    <script>
        $(document).on('pagebeforeshow', "#index",function () {
            $(document).on('click', "#changePage",function () {     
                $.mobile.changePage('second.html', { dataUrl : "second.html?paremeter=123", data : { 'paremeter' : '123' }, reloadPage : false, changeHash : true });
            }); 
        }); 

        $(document).on('pagebeforeshow', "#second",function () {
            var parameters = $(this).data("url").split("?")[1];;
            parameter = parameters.replace("parameter=","");  
            alert(parameter);
        });         
    </script>
   </head>
   <body>
    <!-- Home -->
    <div data-role="page" id="index">
        <div data-role="header">
            <h3>
                First Page
            </h3>
        </div>
        <div data-role="content">
          <a data-role="button" id="changePage">Javascript change page example</a>
                      <a href="second.html" data-transition="slide">Direct link button</a>
        </div> <!--content-->
    </div><!--page-->

  </body>
</html>

HTML 2 - second.html:

<!DOCTYPE html>
  <html>
    <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="widdiv=device-widdiv, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
    <meta name="apple-mobile-web-app-capable" content="yes" />
    <meta name="apple-mobile-web-app-status-bar-style" content="black" />
    <title>
    </title>
    <link rel="stylesheet" href="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.css" />
    <script src="http://www.dragan-gaic.info/js/jquery-1.8.2.min.js">
    </script>
    <script src="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.js"></script>  
   </head>
   <body>
    <!-- Home -->
    <div data-role="page" id="second">
        <div data-role="header">
            <h3>
                Second Page
            </h3>
        </div>
        <div data-role="content">

        </div> <!--content-->
    </div><!--page-->

  </body>
</html>

你还需要知道一件事。只有第一个 HTML 文件可以有多个内部data-role="page". 每个其他 HTML 页面只能有 1 个data-role="page"内部。原因在此处描述。如果您需要更多信息,请给我评论。

于 2013-09-26T10:09:56.123 回答
0

使用单页模板

http://jquerymobile.com/demos/1.3.0-beta.1/docs/pages/page-template.html

那或者您可以将您当前拥有的页面拆分为几个 php 文件,并将它们全部包含到您的主 php 文件中,像往常一样输出标记。

于 2013-09-26T10:06:59.763 回答
0

是的,你可以,这是一个例子:

<li><a href="masterclass.php" data-transition="slide">Master Class</a></li>
于 2013-09-26T10:11:20.067 回答