我知道這個問題已被多次詢問過,但我想爲所有頁面加載動態面板,但它不起作用。 有時CSS樣式不加載或面板不打開.. 有什麼建議嗎? (帶有PageContainer的動態加載面板
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css"
href="css/jquery.mobile-1.4.5/jquery.mobile.black-sidebar-theme.css">
<link rel="stylesheet" type="text/css"
href="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css">
<link rel="stylesheet" type="text/css" href="css/own.css">
<script type="text/javascript" src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
<script type="text/javascript"
src="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
<script type="text/javascript">
$(document).one('pagebeforecreate', function() {
$.mobile.pageContainer.find("div[data-role=page]").each(function() {
var panelHtml = $('<div data-role="panel" data-display="overlay" data-theme="g" id="panel_' + this.id + '">').load("templates/panel/panel.html", function (data) {
});
$(this).append(panelHtml);
$("#panel_" + this.id).panel();
$("#panel_" + this.id).panel().enhanceWithin();
$("#panel_" + this.id).enhanceWithin();
});
});
</script>
</head>
<body>
<div data-role="page" id="page1">
<div data-role="content">
<h2>Content</h2>
<a href="#panel_page1">Open Panel</a>
</div>
</div>
<div data-role="page" id="page2">
<div data-role="content">
<h2>Content</h2>
</div>
</div>
<div data-role="page" id="page3">
<div data-role="content">
<h2>Content</h2>
</div>
</div>
</body>
</html>
我panel.html
<ul data-role="listview" data-theme="g" data-divider-theme="g">
<li data-role="list-divider">Panel</li>
<li><a href="#searchPage">Page1</a></li>
<li><a href="#downloadPage">Page2</a></li>
<li><a href="#playerPage">Pag3</a></li>
</ul>
如果你想在每一頁上相同的面板,你有沒有考慮外部的面板:http://demos.jquerymobile.com/1.4.5/panel-external/ – ezanker
另外,在beforecreate手段代碼做你不需要增強面板:https://jsfiddle.net/ezanker/uuffrfz6/ – ezanker