我在iPhone上遇到了与PhoneGap有关的事件真正的麻烦。该应用在我的Android设备上运行非常流畅,但在我的iPhone上它什么也没有。例如,一个简单的代码是这样的:Phonegap不能在iphone中工作
<!DOCTYPE HTML>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0;" />
<meta charset="utf-8">
<title>WayAcross Mobile Application</title>
<link rel="stylesheet" href="css/jquery.css" />
<link rel="stylesheet" href="css/screen.css" />
<link rel="stylesheet" href="css/login.css" />
<script type="text/javascript" charset="utf-8" src="jquery/jquery.js"></script>
<script type="text/javascript" charset="utf-8" src="jquery/jquery.mobile.js"></script>
<script type="text/javascript" charset="UTF-8" src="javascript/mainJavascript.js"></script>
<script type="text/javascript" charset="utf-8">
// Call onDeviceReady when PhoneGap is loaded.
//
// At this point, the document has loaded but phonegap.js has not.
// When PhoneGap is loaded and talking with the native device,
// it will call the event `deviceready`.
//
function onLoad(){
document.addEventListener("deviceready", onDeviceReady, false);
}
// PhoneGap is loaded and it is now safe to make calls PhoneGap methods
//
function onDeviceReady() {
// Now safe to use the PhoneGap API
alert('ready');
}
</script>
<script type="text/javascript" charset="utf-8" src="javascript/phonegap.js"></script>
</head>
<body onload="onLoad()">
(这是一个代码示例,不与iPhone合作,并与Android版)。
我认为它是一个事件的问题,但我不确定。即使PhoneGap文档中的代码示例也不起作用。 我的环境是:
- 的Mac OSX 10.7.1
- 的Xcode 4.1
- 的PhoneGap 1.1
- jQuery Mobile的1.0RC ,它显示我的唯一的事情是这样的:http://cl.ly/0h462Y2D2F0J0B1B0q1M
在此先感谢。
问候,
Elkas
顺便说一句,我已经安装了OSX 10.7.2狮子和Xcode的4.2现在。即使在IOS5中它不起作用。这真让我抓狂!!! 即使这个简单的代码不起作用。
<!DOCTYPE html>
<html>
<head>
<title>PhoneGap Device Ready Example</title>
<script type="text/javascript" charset="utf-8">
// Call onDeviceReady when PhoneGap is loaded.
//
// At this point, the document has loaded but phonegap.js has not.
// When PhoneGap is loaded and talking with the native device,
// it will call the event `deviceready`.
//
document.addEventListener("deviceready", onDeviceReady, false);
// PhoneGap is loaded and it is now safe to make calls PhoneGap methods
//
function onDeviceReady() {
alert('Hello World');
}
</script>
<script type="text/javascript" charset="utf-8" src="javascript/phonegap.js"</script>
</head>
<body>
</body>
</html>
一切看起来都不错,尝试使用alert()找出它失败的地方。 – sciritai
也试试。如果我在body标签或其他函数中放置了onload =“onDeviceReady()”,它将显示警报,但phonegap“events”仍然不起作用。 =( – Elkas
jQuery mobile应该在*自定义脚本之后添加* – Walf