HTMLエラー(Double id属性)があります。また、pagebeforeshowを使用して、jQMマークアップを拡張します。
これは機能しますか?
HTML
<div data-role="page" id="home" data-add-back-btn="true">
<div id="main" data-role="header" data-position="inline">
<h1>Home</h1>
<a href="#" data-icon="check">Save</a>
</div>
<div data-role="content">
<ul data-role="listview" data-inset="true" data-theme="c" data-dividertheme="f">
<li data-role="list-divider">List View Navigation</li>
<li><a href="#page1">Go to Page1</a></li>
</ul>
</div>
</div>
<div data-role="page" id="page1" data-add-back-btn="true">
<div id="myCustomNavbar" data-role="header" data-position="inline" data-add-back-btn="true">
<!-- dynamic navbar -->
</div>
<div data-role="content">
<p>
Hello Page 1
</p>
</div>
</div>
<div data-role="page" id="page2" data-add-back-btn="true">
<div data-role="header" data-position="inline">
<h1>Page 2</h1>
</div>
<div data-role="content">
<ul data-role="listview" data-inset="true" data-theme="c" data-dividertheme="f">
<li data-role="list-divider">List View Navigation</li>
<li><a href="#home">Go to Home Page</a></li>
</ul>
</div>
</div>
JS
$('#page1').live('pagebeforeshow', function(event, ui) {
var myNav = $('#myCustomNavbar');
var navbar = '<div data-role="navbar">'
+ '<ul>'
+ '<li><a href="#" data-rel="back" data-direction="reverse">Back</a></li>'
+ '<li><a href="#page2">Page 2</a></li>'
+ '</ul>'
+ '</div>';
myNav.html(navbar).trigger( 'create' );
});