我使用jquery mobile创建一个移动应用程序,但在通过changePage加载外部页面(loggedin.html)后,外部页面中的javascript文件未加载,但只有在刷新页面(loggedin.html...通过changePage).如何在不刷新页面的情况下加载外部脚本
我有两组文件: index.html 和login.html。
代码:
1.index.html
<body>
<div data-role="page" id="indexpage">
<div data-role="content">
<a href="" id="next" data-role="button">Load page 2</a>
</div>
</div>
<script src="custom/scripts/index.js" type="text/javascript" ></script>
</body>
脚本(index.js)
$('document').ready(function(){
$('#next').click(function(){
$.mobile.changePage('loggedin.html')
});
});
2.Loggedin.html
<body>
<div data-role="page" id="loggedin">
<div data-role="content">
You are in
</div>
</div>
<script src="custom/scripts/loggedin.js" type="text/javascript" ></script>
</body>
脚本(loggedin.js)
$('document').ready(function(){
$('document').on("pageshow","#loggedin",function(){
console.log('loaded');
});
});
最佳答案
基于此来源:http://demos.jquerymobile.com/1.3.2/faq/scripts-and-styles-not-loading.html
The simplest approach when building a jQuery Mobile site is to reference the same set of stylesheets and scripts in the head of every page. If you need to load in specific scripts or styles for a particular page, we recommend binding logic to the pageinit event (details below) to run necessary code when a specific page is created (which can be determined by its id attribute, or a number of other ways).
关于javascript - Jquery mobile在更改页面后无法加载样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36718342/