JQuery 移动在应用程序中创建单个页面

JQuery mobile creates a single page in the app

一个非常标准的示例,将此代码放在 body 标记之间时,会在应用程序的单个页面上显示所有页面,而不是两个不同的页面相互链接。

<div data-role="page" id="foo">

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

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


<div data-role="page" id="bar">

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

    <div data-role="content">   
        <p>I'm the second in the source order so I'm hidden when the page loads. I'm just shown if a link that references my ID is beeing clicked.</p>      
        <p><a href="#foo">Back to foo</a></p>   
    </div>

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

您需要将 jQuery 个文件添加到您的页面。

工作示例:

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css">
<script src="http://code.jquery.com/jquery-1.11.3.min.js"></script>
<script src="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
</head>
<body>
<div data-role="page" id="foo">

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

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


<div data-role="page" id="bar">

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

    <div data-role="content">   
        <p>I'm the second in the source order so I'm hidden when the page loads. I'm just shown if a link that references my ID is beeing clicked.</p>      
        <p><a href="#foo">Back to foo</a></p>   
    </div>

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

</body>
</html>