$.mobile.loadPage() 和 $("linkBtn").click() 不会在 jquery 手机中加载 <head></head> phonegap
$.mobile.loadPage() and $("linkBtn").click() doesn't load <head></head> in jquery mobile with phonegap
如果用户已经注册,我会在应用程序启动时强制点击锚点。
当我这样做并转到第 2 页时,所有脚本 src 都不会加载。
我不确定这里出了什么问题..我相信我按照手册强制链接..
- page1.html 是单-paged.html -> 应用程序启动时首先加载 -> 重定向到 page2.html 由下面的 page1.js 提供。
- page2.html是多paged.html
从page1.html到page2.html的导演是:
$(document).on('pageinit', function(){
$.mobile.loadPage("Page2.html");
$("#startbtn").click();
});
这里是page1.html
<!DOCTYPE html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<script type="text/javascript" charset="utf-8" src="jquery.mobile/jquery-1.11.2.min.js"></script>
<script type="text/javascript" charset="utf-8" src="cordova.js"></script>
<script type="text/javascript" charset="utf-8" src="jquery.mobile/jquery.mobile-1.4.5.min.js"></script>
<link rel="stylesheet" href="jquery.mobile/jquery.mobile-1.4.5.min.css" />
<script type="text/javascript" charset="utf-8" src="js/page1.js"></script>
</head>
<body>
<div data-role="page">
<a href="page2.html" data-rel='external' data-role='button' id="startbtn">START!</a>
</div>
</body>
</html>
我要从 Why aren't my scripts and styles loading?
复制粘贴
jQuery Mobile's AJAX navigation system only loads in the contents of
the page wrapper, the scripts and styles in the head are discarded so
you need to plan how to load and organize these assets.
更多解释
This means that any scripts and styles referenced in the head of a
page won't have any effect when a page is loaded via AJAX, but they
will execute if the page is requested normally via HTTP. When
scripting jQuery Mobile sites, both scenarios need to be considered.
The reason that the head of a page is ignored when requested via AJAX
is that the potential of re-executing the same JavaScript is very high
(it's common to reference the same scripts in every page of a site).
Due to the complexity of attempting to work around that issue, we
leave the task of executing page-specific scripts to the developer,
and assume head scripts are only expected to execute once per browsing
session.
可能的解决方案:在父页面中插入您的样式和脚本(在您的情况下为 page1.html
)。了解如何在 JQM 中使用 on
live
方法。
如果用户已经注册,我会在应用程序启动时强制点击锚点。 当我这样做并转到第 2 页时,所有脚本 src 都不会加载。 我不确定这里出了什么问题..我相信我按照手册强制链接..
- page1.html 是单-paged.html -> 应用程序启动时首先加载 -> 重定向到 page2.html 由下面的 page1.js 提供。
- page2.html是多paged.html
从page1.html到page2.html的导演是:
$(document).on('pageinit', function(){
$.mobile.loadPage("Page2.html");
$("#startbtn").click();
});
这里是page1.html
<!DOCTYPE html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<script type="text/javascript" charset="utf-8" src="jquery.mobile/jquery-1.11.2.min.js"></script>
<script type="text/javascript" charset="utf-8" src="cordova.js"></script>
<script type="text/javascript" charset="utf-8" src="jquery.mobile/jquery.mobile-1.4.5.min.js"></script>
<link rel="stylesheet" href="jquery.mobile/jquery.mobile-1.4.5.min.css" />
<script type="text/javascript" charset="utf-8" src="js/page1.js"></script>
</head>
<body>
<div data-role="page">
<a href="page2.html" data-rel='external' data-role='button' id="startbtn">START!</a>
</div>
</body>
</html>
我要从 Why aren't my scripts and styles loading?
复制粘贴jQuery Mobile's AJAX navigation system only loads in the contents of the page wrapper, the scripts and styles in the head are discarded so you need to plan how to load and organize these assets.
更多解释
This means that any scripts and styles referenced in the head of a page won't have any effect when a page is loaded via AJAX, but they will execute if the page is requested normally via HTTP. When scripting jQuery Mobile sites, both scenarios need to be considered. The reason that the head of a page is ignored when requested via AJAX is that the potential of re-executing the same JavaScript is very high (it's common to reference the same scripts in every page of a site). Due to the complexity of attempting to work around that issue, we leave the task of executing page-specific scripts to the developer, and assume head scripts are only expected to execute once per browsing session.
可能的解决方案:在父页面中插入您的样式和脚本(在您的情况下为 page1.html
)。了解如何在 JQM 中使用 on
live
方法。