所以我得到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设备,如果没有它,它就会永远不会闪光。
任何帮助将不胜感激!也许我在这里错过了一些简单的东西。
我也试过jQuery和jQuery Mobile的不同版本组合而没有运气。 我正在运行Android Phonegap版本和cordova-2.3.0。我最近尝试升级到cordova-2.4.0以查看是否有帮助,但没有...
更新:LogCat / DDMS中没有引发错误
答案 0 :(得分:0)
尝试放scripts above jquery mobile library.
:
<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/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>
<script type="text/javascript" src="js/jquery.mobile-1.2.0.min.js"></script>
<script type="text/javascript">
$(document).on('pageinit', function($){
app.initialize();
});
</script>
答案 1 :(得分:0)
前一段时间我遇到了同样的问题,最后我扔掉了phonegap的发射器。
我建议这样做:
<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">
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
// your functions here
}
</script>
我希望它有所帮助
答案 2 :(得分:0)
我注意到浏览器不起作用,但使用模拟器或PhoneGap构建ondeviciready事件并且相同的示例有效!
答案 3 :(得分:0)
即使将库添加到头部后我也遇到了完全相同的问题,但是当我将cordova.js移到jquery-mobile下面时,设备已经开始再次启动。
<head>
<script type="text/javascript" src="jqueryMobile/jquery-1.11.1.min.js"></script>
<script type="text/javascript" src="jqueryMobile/jquery.mobile-1.4.3.min.js"></script>
<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript" src="js/index.js"></script>
<script type="text/javascript">
app.initialize();
</script>
</head>