Jquery mobile 如何为所有jQuery移动页面使用模板?
请看:页脚模板:Jquery mobile 如何为所有jQuery移动页面使用模板?,jquery-mobile,Jquery Mobile,请看:页脚模板: <!-- Templates --> <script type="text/template" id="templateFooter"> <div data-role="navbar"> <ul> <li><a href="#about">About</a></li> <li><a href="
<!-- Templates -->
<script type="text/template" id="templateFooter">
<div data-role="navbar">
<ul>
<li><a href="#about">About</a></li>
<li><a href="#contact">Contact</a></li>
</ul>
</div>
</script>
这是可行的,但我并不喜欢使用$(function(),但如果有页面显示,我需要加载它,因此pageinit或pageshow没有帮助。如果有帮助,我将继续使用knockout.js
还有更好的方法吗?还有一个pageshow事件,即使用户导航到页面,也会触发该事件,通过按“后退”按钮等…它会弹出页面div
我将它用于在后续访问之间,或者甚至用户只需按一下键,就可以更改大量动态数据的页面。谢谢!这正是我想要的:每页运行一次。引用文档:请注意,通过绑定到pagebeforecreate,您可以在jQuery Mobile的默认小部件自动初始化之前操作标记。例如e、 假设您希望通过JavaScript而不是在HTML源代码中添加数据属性,这是您将使用的事件。
function getTemplateFooter() {
//return footer text here
}
$("div:jqmData(role='page')").live("pagebeforecreate",function() {
// get the footer of the page
// if footer doesn't exist on page, insert it where you want it... in this case after role="content"?
var $content =$(this).page().find('div:jqmData(role="content")');
$content.after(getTemplateFooter());
}
$(function() {
$('div[data-role=footer]').html($('#templateFooter').html());
$.mobile.activePage.trigger('create');
});
function getTemplateFooter() {
//return footer text here
}
$("div:jqmData(role='page')").live("pagebeforecreate",function() {
// get the footer of the page
// if footer doesn't exist on page, insert it where you want it... in this case after role="content"?
var $content =$(this).page().find('div:jqmData(role="content")');
$content.after(getTemplateFooter());
}