我有一个基本的 jQuery Mobile 页面,如下所示:
<div data-role="page" id="home">
</div>
<div data-role="page" id="products">
</div>
一切都按预期工作,除非我想从外部链接链接到产品页面。我试过了: mysite.com/mobile/default.aspx#products 但仅显示主页。有没有办法让外部链接显示产品页面?
最佳答案
简短的回答是,您无法直接链接到多页文档中的特定页面。
不幸的是,jQuery Mobile 的工作方式是,当您链接到具有多个“页面”的页面时,默认情况下它只会加载第一个页面,要加载整个外部多页文档,您需要不使用 ajax 加载页面(例如添加 rel="external"
,或者如果您想使用 ajax 加载页面,可以使用 subpages plugin 。
就链接而言,您应该分开您的页面,或者通过ajax预加载外部多页文档(使用我上面链接到的插件,或者如果您愿意的话手动),然后链接将其作为内部页面。
It's important to note that if you are linking from a mobile page that was loaded via Ajax to a page that contains multiple internal pages, you need to add a rel="external" or data-ajax="false" to the link. This tells the framework to do a full page reload to clear out the Ajax hash in the URL. This is critical because Ajax pages use the hash (#) to track the Ajax history, while multiple internal pages use the hash to indicate internal pages so there will be conflicts in the hash between these two modes.
For example, a link to a page containing multiple internal pages would look like this:
<a href="multipage.html" rel="external">Multi-page link</a>
关于jquery - 如何从外部页面链接到jquery移动子页面?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13961372/