gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-27 23:04:29 27 4
gpt4 key购买 nike

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

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