jquery - 如何从外部页面链接到jquery移动子页面?

标签 jquery jquery-mobile

我有一个基本的 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预加载外部多页文档(使用我上面链接到的插件,或者如果您愿意的话手动),然后链接将其作为内部页面。

来自Documentation

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/

相关文章:

javascript - 使用 JavaScript 检查图像 URL 的可靠方法

javascript - 将值插入到光标所在的 TEXTAREA 中

listview - jQuery 获取动态 ListView 的选定项

javascript - Jquery Mobile 1.4.5 设备中的虚拟键盘隐藏页面底部的表单输入

codeigniter - Phonegap 和 Jquery 移动应用程序使用 Codeigniter Ion Auth 后端进行登录

jquery - 使用 JQuery 执行带有 POST 变量的 GET 请求

javascript - 模态下拉列表

javascript - 检查字符串值是否等于 - (减号)

javascript - 如何清除 jQueryMobile 中外部页面的文本字段值

cordova - 升级 JQuery Mobile 应该做什么?