gpt4 book ai didi

javascript - Phonegap 事件在 iPhone 中不起作用

转载 作者:可可西里 更新时间:2023-11-01 04:44:46 27 4
gpt4 key购买 nike

我在 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 文档中的代码示例也不起作用。我的环境是:

  1. Mac 操作系统 10.7.1
  2. Xcode 4.1
  3. PhoneGap 1.1
  4. jQuery 移动版 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>

最佳答案

尝试像这样放置 addeventlistener 和 document.ready.. 为我解决了同样的问题。

$(document).ready(function(){
document.addEventListener("deviceready",function(){

},false);
});

关于javascript - Phonegap 事件在 iPhone 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7743689/

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