したがって、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 イベントを呼び出してみました。
そして、私はこの解決策に従ってみましたが、その下に投稿された他の解決策は役に立ちませんでした。
JQuery-Mobile/Phonegapを一緒に使用する正しい方法は?
しかし、同じことが起こります。jQuery Mobile deviceready を使用すると、起動することはありません。それがなければ、正常に起動します。
どんな助けでも大歓迎です!たぶん、ここで単純なものが欠けているだけです。
また、jQuery と jQuery Mobile のさまざまなバージョンの組み合わせを試してみましたが、うまくいきませんでした。Android Phonegap バージョンと cordova-2.3.0 を実行していました。私は最近、cordova-2.4.0 にアップグレードして、それが役立つかどうかを確認しましたが、何もしませんでした...
更新: LogCat/DDMS でエラーがスローされません