2017-01-30 70 views
-1

我想使用apache cordova和jQuery做一個簡單的應用程序。我的問題如下:當我在瀏覽器(在電腦上)打開page.html時,它會起作用。當我做一個.apk它不起作用。jQuery不與apache cordova一起工作

我的代碼是這樣的:

<!DOCTYPE html> 
<!-- 
    Licensed to the Apache Software Foundation (ASF) under one 
    or more contributor license agreements. See the NOTICE file 
    distributed with this work for additional information 
    regarding copyright ownership. The ASF licenses this file 
    to you under the Apache License, Version 2.0 (the 
    "License"); you may not use this file except in compliance 
    with the License. You may obtain a copy of the License at 

    http://www.apache.org/licenses/LICENSE-2.0 

    Unless required by applicable law or agreed to in writing, 
    software distributed under the License is distributed on an 
    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 
    KIND, either express or implied. See the License for the 
    specific language governing permissions and limitations 
    under the License. 

    270258529759-mhdktnmarr8givv93t3druvmtc4onkei.apps.googleusercontent.com 
    kZMIedwLUinqBjF2oVFuIjaD 

--> 
<html> 
    <head> 
     <!-- 
     Customize this policy to fit your own app's needs. For more guidance, see: 
      https://github.com/apache/cordova-plugin-whitelist/blob/master/README.md#content-security-policy 
     Some notes: 
      * gap: is required only on iOS (when using UIWebView) and is needed for JS->native communication 
      * https://ssl.gstatic.com is required only on Android and is needed for TalkBack to function properly 
      * Disables use of inline scripts in order to mitigate risk of XSS vulnerabilities. To change this: 
       * Enable inline JS: add 'unsafe-inline' to default-src 
     --> 



     <meta http-equiv="Content-Security-Policy" content="default-src 'self' data: gap: https://ssl.gstatic.com 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src *; img-src 'self' data: content:;"> 
     <meta name="format-detection" content="telephone=no"> 
     <meta name="msapplication-tap-highlight" content="no"> 
     <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width"> 
     <meta name="google-signin-client_id" content="270258529759-mhdktnmarr8givv93t3druvmtc4onkei.apps.googleusercontent.com"> 
     <link rel="stylesheet" type="text/css" href="css/index.css"> 
     <title>Hello World</title> 

     <link rel="stylesheet" href="jquery.css"> 

     <script src="jquery.js"></script> 
     <script src="defaul.js"></script> 
     <script src="mobileJquery.js"></script> 
     <script type="text/javascript" src="cordova.js"></script> 
     <script type="text/javascript" src="js/index.js"></script> 

    </head> 
    <body> 

      <div data-role="page" id="pageone"> 

    <div data-role="panel" data-position="left" data-display="overlay" id="rightMenu"> 
     <h1>Navigation</h1> 
     <hr /> 
     <a href="#" class="ui-btn ui-icon-arrow-r ui-btn-icon-right">Home Page</a> 
     <a href="page2.html" class="ui-btn ui-icon-arrow-r ui-btn-icon-right">Scan a Barcode</a> 
     <a href="favorites.html" class="ui-btn ui-icon-arrow-r ui-btn-icon-right">Favorites List</a> 
     <a href="pow.html" class="ui-btn ui-icon-arrow-r ui-btn-icon-right">P.O.W.</a> 
     <a href="contact.html" class="ui-btn ui-icon-arrow-r ui-btn-icon-right">Contact Us</a> 
    </div><!-- /panel --> 

    <div data-role="header"> 
     <a href="#rightMenu" id="mypanel" class="ui-btn ui-icon-bars ui-btn-icon-right">Menu</a> <h1>Header Text</h1> 
    </div> 


    <center><img src="img/loading.gif" id="loading"/></center> 

    <div data-role="main" class="ui-content" id="content"> 

      <center><div id="inText">Πριν μποριτε να χρεισιμοποιητε αυτη την εφαρμογη, παρακαλω εγγραφειτε, η αν ειστε ηδη μελος, εισαγετε τον κωδικο σας.</div></center> 

      <div id="rForm"> 
      <br /> 
      <br /> 
      <center>Παρακαλω εισαγγετε την ηλεκτρονικη σας διευθηνση και εναν κωδικο.</center> 
      <br /> 
      <input type="text" id="email" label="email" placeholder="[email protected]" /> 
      <input type="password" id="password" placeholder="password" /> 
      <center><button id="submit">Εγγραφη</button> 
      </div> 

      <div id="loForm"> 
      <br /> 
      <br /> 
      <center>Για να συνδεεστε, παρακαλω εισαγγετε τον κωδικο προσβασης σας</center> 
      <br /> 
      <input type="text" id="emailLo" placeholder="[email protected]" /> 
      <center><button id="loginAl">Συνδεση</button></center> 
      </div> 

      <button class="ui-button ui-widget ui-corner-all" id="register">Εγγραφη</button> 

      <button class="ui-button ui-widget ui-corner-all" id="login">Εισαγωγη κώδικας</button> 

    </div> 

    <div data-role="footer" data-position="fixed"> 
     <h1>Footer Text</h1> 
    </div> 
    </div> 


    </body> 
</html> 

和我defaul.js:

$('#content').hide(); 

$(document).ready(function(){ 

    $('#rForm').hide(); 
    $('#loForm').hide(); 
    $('#loading').hide(); 
    $('#content').show(); 

$(document).bind("deviceready", function(){ 

//trigger when click on register button 
    $('#register').click(function(){ 

     $(this).hide(); 
     $('#login').hide(); 
     $('#inText').hide(); 
     $('#rForm').show(function(){ 

     }); 
    }); 

//trigger when click on login button 
    $('#login').click(function(){ 

     $(this).hide(); 
     $('#register').hide(); 
     $('#inText').hide(); 
     $('#loForm').show(function(){ 



     }); 

    }); 

//end of document ready 
}); 
}); 

的jQuery Mobile的設計工作得很好,但jQuery函數不工作。

編輯:@Nanne我沒有得到任何錯誤。但是當我在我的設備上打開它時,它不會隱藏#rForm和#loForm。而事件不工作

+2

「功能不工作」是不是最好的錯誤描述過:) ..你可能想要包括實際發生的事情。你會得到一個錯誤,如果是的話,你是否嘗試並添加console.logs等(ow,請將它添加到你的問題中,而不是對它們進行評論,因爲這會使整個問題難以理解)。另外,請儘量使用盡可能少的代碼顯示問題的實例,所以我們確信它不在額外的代碼中 ! – Nanne

回答

0

請把您的點擊事件「deviceready」事件之外

希望這對你的工作:)

相關問題