J'essaie de faire une application simple en utilisant apache cordova et jQuery. Mon problème est le suivant: quand j'ouvre le page.html dans mon navigateur (sur l'ordinateur) cela fonctionne toattaly. Quand je fais un .apk ça ne marche pas.jQuery ne fonctionne pas avec apache cordova
Mon code est le suivant:
<!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>
et mes 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
});
});
La conception jQuery mobile fonctionne très bien, mais les fonctions jQuery ne fonctionnent pas.
Modifier: @Nanne Je ne reçois aucune erreur. Mais quand je l'ouvre sur mon appareil, il ne masque ni #rForm et #loForm. Et les événements ne fonctionnent pas
fonction « ne fonctionnent pas » est pas la meilleure description de l'erreur jamais :) .. Vous pourriez vouloir inclure ce qui se passe réellement. Avez-vous une erreur, si oui, avez-vous essayé d'ajouter console.logs, etc. (ow, et s'il vous plaît, ajoutez-le à votre question et ne les commentez pas, car cela rendrait difficile la lecture de tout le problème). Aussi, essayez de faire un exemple qui montre le problème avec le moins de code possible, donc nous sommes sûrs que ce n'est pas dans le code supplémentaire ! – Nanne