javascript - Jquery mobile在更改页面后无法加载样式

标签 javascript jquery html jquery-mobile

我使用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/

相关文章:

PHP-jquery 根据另一个组合框中的选择填充一个组合框?

javascript - 基本的 jQuery 淡入、淡出问题

jquery - 在移动到另一个页面之前点击 <a> 标签上的声音

html - 制作此布局(CSS 或表格)的最佳方式是什么?

javascript - sIFR 字体大小问题

javascript 函数 stopi 不起作用

javascript - jQuery 每个函数在同一元素中输出多个选择器

javascript - 在循环中添加基于数据属性的 jQuery 验证规则

javascript - Electron - openShowDialog 未定义

html - 如何在 HTML 中制作底部固定位置菜单?