简体   繁体   中英

jQuery isn't working with apache cordova

I'm trying to make a simple application using apache cordova and jQuery. My problem is the following: when I open the page.html in my browser (on computer) it works toattaly. When I make an .apk it doesnt work.

My code is this:

<!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="user_email@service.dot" />
            <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="user_email@service.dot" />
            <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>

and my 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
});
});

The jQuery mobile design is working just fine, but the jQuery functions are not working.

Edit: @Nanne I'm not getting any errors. But when I open it on my device it doesn't hide neither #rForm and #loForm. And the events don't work

Please put your click event outside of "deviceready" event

Hope it's work for you :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM