我正在尝试在单个index.html中创建一个带有多个页面的导航栏的jQuerymobile应用。我正在使用模板Multi-page template structure
很遗憾,我无法使导航栏显示不同的页面。这是我的代码:
我也确实使用了脚本“ pageLoader.js”来强制加载页面。但这也不起作用。这是我的pageLoader.js:
<!doctype html>
<html>
<head>
<title>My Page</title>
<!--https://jquerymobile.com/download/-->
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.css" />
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script src="http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.js"></script>
</head>
<body>
<!--POST page 1-->
<div data-role="page" id="postPage">
<div data-role="header">
<h1>I'm a header</h1>
<div data-role="navbar">
<ul>
<li><a href="#postPage">POST</a></li>
<li><a href="#getPage">GET</a></li>
<li><a href="#putPage">PUT</a></li>
<li><a href="#deletePage">DELETE</a></li>
</ul>
</div><!-- /navbar -->
</div><!-- /header -->
<div role="main" class="ui-content">
<label for="key">key:</label>
<input type="text" name="key" id="key" placeholder="enter your key" value="" data-clear-btn="true">
<label for="value">value:</label>
<input type="text" name="value" id="value" placeholder="enter your value" value="" data-clear-btn="true">
<button onclick="saveValue()"> Store Key</button>
<p id="status">Status: No Activity</p>
</div><!-- /content -->
<div data-role="footer">
<h4>My Footer</h4>
</div><!-- /footer -->
<!--get Page 2-->
<div data-role="page" id ='getPage'>
<div data-role="header">
<h1>I'm a header</h1>
<div data-role="navbar">
<ul>
<li><a href="#postPage">POST</a></li>
<li><a href="#getPage">GET</a></li>
<li><a href="#putPage">PUT</a></li>
<li><a href="#deletePage">DELETE</a></li>
</ul>
</div><!-- /navbar -->
</div><!-- /header -->
<div role="main" class="ui-content">
<label for="key">key:</label>
<input type="text" name="key" id="key" placeholder="enter your key" value="" data-clear-btn="true">
<button onclick ="getValue()"> Get Value</button>
<p id="status">Status: No Activity</p>
</div><!-- /content -->
<div data-role="footer">
<h4>My Footer</h4>
</div><!-- /footer -->
</div><!-- /page -->
<script src="scripts/client.js" type="text/javascript"></script>
<script src="scripts/pageLoader.js" type="text/javascript"></script>
</body>
</html>
我还尝试使用脚本来强制更改页面。我将pageLoader.js脚本用于以下内容:
$(document).on("pageshow", function(){
if($('.ui-page-active').attr('id') === 'postPage'){
$.mobile.changePage("#postPage");
} else if ($('.ui-page-active').attr('id') === 'getPage'){
$.mobile.changePage("#getPage");
}
});
任何帮助将不胜感激。