【发布时间】:2013-02-05 06:17:22
【问题描述】:
所以我已经让 jQuery 1.8.2 与 Phonegap 一起使用没有问题,但是只要我添加 jquery.mobile.1.2.0,默认的 Phonegap 示例就会中断。 deviceready 事件停止触发。
index.html
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="format-detection" content="telephone=no" />
<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" />
<link rel="stylesheet" type="text/css" href="css/index.css" />
<title>Hello World</title>
</head>
<body>
<div class="app">
<h1>Apache Cordova</h1>
<div id="deviceready" class="blink">
<p class="event listening">Connecting to Device</p>
<p class="event received">Device is Ready</p>
</div>
</div>
<input type="text" name="firstname" id="firstname" />
<a href="#" class="btn" onclick="displayHello();">Say Hello</a>
<script type="text/javascript" src="cordova-2.4.0.js"></script>
<script type="text/javascript" src="js/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="js/jquery.mobile-1.2.0.min.js"></script>
<script type="text/javascript" src="js/index.js"></script>
<script type="text/javascript">
app.initialize();
function displayHello(){
var name = document.getElementById("firstname").value;
navigator.notification.alert("My name is "+ name);
}
</script>
</body>
</html>
index.js
var app = {
// Application Constructor
initialize: function() {
this.bindEvents();
},
// Bind Event Listeners
//
// Bind any events that are required on startup. Common events are:
// 'load', 'deviceready', 'offline', and 'online'.
bindEvents: function() {
document.addEventListener('deviceready', this.onDeviceReady, false);
},
// deviceready Event Handler
//
// The scope of 'this' is the event. In order to call the 'receivedEvent'
// function, we must explicity call 'app.receivedEvent(...);'
onDeviceReady: function() {
app.receivedEvent('deviceready');
},
// Update DOM on a Received Event
receivedEvent: function(id) {
var parentElement = document.getElementById(id);
var listeningElement = parentElement.querySelector('.listening');
var receivedElement = parentElement.querySelector('.received');
listeningElement.setAttribute('style', 'display:none;');
receivedElement.setAttribute('style', 'display:block;');
console.log('Received Event: ' + id);
}
};
所以这是Phonegap自带的默认代码示例,我只是添加了
<script type="text/javascript" src="js/jquery.mobile-1.2.0.min.js"></script>
在 index.html 中。
不确定发生了什么,因为似乎其他人已经让 Phonegap 和 jQuery Mobile 一起工作得很好。
我已经尝试过将 js 简化,只调用 deviceready 事件。
我已经尝试按照这个解决方案和下面发布的另一个解决方案无济于事。
Correct way of using JQuery-Mobile/Phonegap together?
但同样的事情也会发生。使用 jQuery Mobile deviceready 永远不会触发,没有它,它可以正常触发。
任何帮助将不胜感激!也许我只是在这里遗漏了一些简单的东西。
我还尝试了 jQuery 和 jQuery Mobile 的不同版本组合,但没有成功。 我正在运行 Android Phonegap 版本和 cordova-2.3.0。我最近尝试升级到 cordova-2.4.0 看看是否有帮助,但没有任何帮助......
更新:LogCat/DDMS 中没有抛出错误
【问题讨论】:
-
我在正文中加载了所有脚本,我将它们移动到 并且它似乎工作。我目前正在另一台计算机上对其进行测试,我回家后也会尝试以确保。正如我之前应该做的那样,我查找了 phonegap 的 onDeviceReady 事件,他们的完整示例在头部加载了 javascript 并使用 调用 app.initialize(); docs.phonegap.com/en/2.4.0/…
-
将库移动到 似乎可以解决问题。
-
那么,您找到解决方案了吗?
标签: android jquery cordova jquery-mobile mobile