4

したがって、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 でエラーがスローされません

4

4 に答える 4

0

ブラウザが機能しないことに気づきましたが、エミュレータまたはPhoneGapビルドondevicireadyイベントを使用すると、同じ例が機能します。

于 2013-02-24T19:07:02.467 に答える
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>

役立つことを願っています

于 2013-02-20T09:52:02.757 に答える
0

ライブラリをヘッドに追加した後もまったく同じ問題が発生しましたが、cordova.js を jquery-mobile の下に移動するとすぐに、deviceready が再び起動し始めました。

<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>
于 2014-08-12T20:06:19.643 に答える
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>
于 2013-02-20T09:44:57.780 に答える