Javascript Phonegap多页
我目前正在科尔多瓦开发一个应用程序。因为我有更多的页面,所以我尝试添加一个菜单。在第一个页面(index.html)上有一些输出,在第二个文件(settings.html)上,我想向外部服务器发出Ajax请求 在Javascript Phonegap多页,javascript,jquery,html,ajax,cordova,Javascript,Jquery,Html,Ajax,Cordova,我目前正在科尔多瓦开发一个应用程序。因为我有更多的页面,所以我尝试添加一个菜单。在第一个页面(index.html)上有一些输出,在第二个文件(settings.html)上,我想向外部服务器发出Ajax请求 在-标记所有样式表中,包括jQuery和Cordova。在-标记中进行了一些Ajax调用 <head> <meta charset="utf-8" /> <meta name="format-detection" content="telephone=no"
-标记所有样式表中,包括jQuery和Cordova。在
-标记中进行了一些Ajax调用
<head>
<meta charset="utf-8" />
<meta name="format-detection" content="telephone=no" />
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.11.4/themes/start/jquery-ui.css" />
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.5/jquery.mobile.structure-1.4.5.min.css" />
<script type="text/javascript" src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
<script type="text/javascript" src="http://code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<script type="text/javascript" src="cordova.js"></script>
</head>
<body onload="onLoad();">
<div data-role="controlgroup" data-corners="false">
<a href="index.html">Home</a>
<a href="settings.html">Settings</a>
</div>
<!-- Ajax Requests -->
</body>
如果我点击设置,我会进入html页面,代码会显示出来,但是jQuery/js代码不会被执行。(我尝试发出警报,但不起作用)
你能告诉我我有什么可能包含另一个带有js代码的页面吗
谢谢 您需要包含一个脚本,该脚本将在页面完全加载到DOM中时触发
<script>
$(document).ready(function(){
-- call your$.ajax({}) here --
});
</script>
$(文档).ready(函数(){
--在这里调用$.ajax({})--
});
或
(功能(){
在这里调用$.ajax({})--
}();
如果您正在使用,您可以像这样对多个页面使用单页应用程序
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css">
<script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
<script src="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
</head>
<body>
<div data-role="page" id="index">
<div data-role="header">
<h1>Home</h1>
</div>
<div data-role="content" class="ui-content" >
<p>Home Page</p>
<a data-role="none" href="#setting">Setting</a>
</div>
</div>
<div data-role="page" id="setting">
<div data-role="header">
<h1>Setting</h1>
<a href="" data-rel="back" >Back</a>
</div>
<div data-role="content" class="ui-content" >
<p>Setting Page</p>
</div>
</div>
</body>
<script>
$(document).on("pagebeforeshow","#index",function(){
// You ajax call for index page
});
$(document).on("pagebeforeshow","#setting",function(){
// You ajax call for setting page
});
</script>
<html>
家
主页
背景
设置页
$(文档)。在(“pagebeforeshow”,“索引”,函数()上){
//您可以调用索引页
});
$(文档)。在(“pagebeforeshow”、“#设置”和函数()上{
//您可以调用ajax来设置页面
});
因此我通过
将脚本包含在settings.html中,并将您的函数放在settings.html页面的头部。页面完全加载后,它将执行该函数。谢谢!是否有可能从“#index”触发事件如果调用了事件,在启动页面时?我需要这两个事件,因为调用页面时,事件也应该触发。
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css">
<script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
<script src="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
</head>
<body>
<div data-role="page" id="index">
<div data-role="header">
<h1>Home</h1>
</div>
<div data-role="content" class="ui-content" >
<p>Home Page</p>
<a data-role="none" href="#setting">Setting</a>
</div>
</div>
<div data-role="page" id="setting">
<div data-role="header">
<h1>Setting</h1>
<a href="" data-rel="back" >Back</a>
</div>
<div data-role="content" class="ui-content" >
<p>Setting Page</p>
</div>
</div>
</body>
<script>
$(document).on("pagebeforeshow","#index",function(){
// You ajax call for index page
});
$(document).on("pagebeforeshow","#setting",function(){
// You ajax call for setting page
});
</script>
<html>