简体   繁体   English

包括jquery移动多页面网站中的页眉和页脚

[英]including the header and footer in jquery mobile multiple page site

I am creating a jquery mobile web app which contains 3 pages, my header/nav for these pages doesnt change but in all the examples Ive seen the header and footer is added to each page. 我正在创建一个jquery移动网络应用程序,其中包含3个页面,我的标题/导航这些页面没有变化,但在所有示例中,我看到页眉和页脚添加到每个页面。 Is it possible just to add 1 nav and 1 footer then just switch the pages main content in and out like this structure: 是否可以只添加1个导航和1个页脚,然后只需将此主要内容切换为此结构:

<div id="header" data-role="header"></div>
<div id="page1" data-role="page">content</div>
<div id="page2" data-role="page">content</div>
<div id="page3" data-role="page">content</div>
<div id="footer" data-role="footer"></div>

Basically is there a way of just showing/hiding the main content and doing nothing with the header and footer? 基本上有一种方法可以显示/隐藏主要内容,并且不对页眉和页脚做任何事情吗?

Any advice on this would be great Kyle 对此有任何建议将是伟大的凯尔

No, unfortunately JQM doesn't support this (yet), you'll need to add your role=header and role=footer on EVERY role=page you got (all 3 of them). 不,不幸的是JQM不支持这个(还),你需要在你获得的每个角色=页面上添加你的role = header和role = footer(所有3个)。

See documentation 文档

I would stick to $.mobile.changePage() since that takes care of hashing and a lot of other events and not just use JQuery to .load() new content... 我会坚持使用$ .mobile.changePage(),因为它负责散列和许多其他事件,而不只是使用JQuery来.load()新内容......

Hope this helps 希望这可以帮助

Have a look at the load() method in jQuery -> http://api.jquery.com/load/ 看看jQuery中的load()方法 - > http://api.jquery.com/load/

Here is an exmaple : 这是一个例子:

$('#navigation').click(function() {
   $('#page1').load('page1.html');
});

This means that when something with an id of navigation is clicked it will call the load() function and replace the div with id of page1 with the contents of the loaded file. 这意味着当单击具有navigation id的内容时,它将调用load()函数并将id为page1div替换为已加载文件的内容。

you can use .load() in jQuery 你可以在jQuery中使用.load()

for example in every page you will have this: 例如,在每个页面中,您将拥有:

<div data-role="footer" class="ui-footer"></div>

now build this function: 现在构建这个功能:

function goTo(pageURL, transitionType) {
  $.mobile.changePage(pageURL, transitionType);
  $('.ui-footer').load('assets/includes/footer.html');
}

now when you move between pages, try onclick (or from code if you like) call: 现在当您在页面之间移动时,请尝试onclick (或者如果您愿意,可以从代码中调用):

goTo('home.html','slideup');

that would do the trick (this is what I use) 会做的伎俩(这是我用的)

you can do the same for the headers as well. 你也可以为标题做同样的事情。

keep in mind if the header or footer content changes for each version of the app (such as localization) you have to call this first, then fill in the localization text or anything else. 请记住,如果每个版本的应用程序(如本地化)的页眉或页脚内容发生更改,您必须先调用它,然后填写本地化文本或其他任何内容。

I hope this helps for your purpose 我希望这有助于您的目的

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM