【发布时间】:2011-10-12 16:57:10
【问题描述】:
我在 iPhone 中的 PhoneGap 事件中遇到了真正的麻烦。该应用程序在我的 android 设备上运行非常流畅,但在我的 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
提前致谢。
问候,
埃尔卡斯
顺便说一句,我现在已经安装了 OSX Lion 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() 记录内容以找出失败的地方。
-
也试试。如果我将 onload="onDeviceReady()" 放在正文标签或其他函数中,它会显示警报,但 phonegap“事件”仍然不起作用。 =(
-
jQuery mobile 应该在 自定义脚本之后添加。
标签: javascript iphone ios jquery-mobile cordova