gpt4 book ai didi

jQuery mobile 预取通过 Ajax 加载内容的页面

转载 作者:行者123 更新时间:2023-12-03 22:53:01 25 4
gpt4 key购买 nike

我在单页面模板中使用 jQuery mobile(每个页面都是一个单独的 html 文件)。我想预取一个通过 Ajax 加载内容的页面。我将预取代码放在第一页的 Document.ready() 函数中

$.mobile.loadPage("my-projects.html", { showLoadMsg: false });

在我想要预取的第二页的 Document.ready() 函数中调用 ajax。当我们对该页面进行 preftech 时,不会发生此 ajax 调用。有没有办法实现这一点。请帮忙

最佳答案

jQuery Mobile 内置了预取功能,您所要做的就是将 data-prefetch 属性添加到链接到远程页面的链接中:

<a href="prefetchThisPage.html" data-prefetch> ... </a>

来源:http://jquerymobile.com/demos/1.1.0/docs/pages/page-cache.html

一般来说,当您通过 AJAX 拉入页面时,document.ready 函数不会触发。不过,您可以使用 jQuery Mobile Page 事件,例如 pageinit。例如:

$(document).delegate('#my-page-id', 'pageinit', function () {
$.mobile.loadPage("my-projects.html", { showLoadMsg: false });
});

关于jQuery mobile 预取通过 Ajax 加载内容的页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11051806/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com