2017-01-30 74 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”事件之外

希望这对你的工作:)

相关问题