Jquery not working with phoneGap

前端 未结 3 878
花落未央
花落未央 2021-01-28 04:04

I am using phonegap, and this code loads perfectly in my android mobile.But When i click the button it does not shows the text.

    


        
相关标签:
3条回答
  • 2021-01-28 04:15

    try using this:

    <!DOCTYPE html>
    <html>
    <head>
      <script type="text/javascript" charset="utf-8" src="cordova-2.4.0.js"></script>
      <script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js">
      </script>
      <script>
         $(document).on('pageinit', function(event){
            $("#btn1").click(function(){
                $("#test1").text("Hello world!");
            });
         });
      </script>
      <script src="http://code.jquery.com/mobile/1.3.0/jquery.mobile-1.3.0.min.js">
      </script>
    </head>
    
    <body>
       <p id="test1"></p>
       <button id="btn1">Set Text</button>
    
    </body>
    </html>
    

    Instead of doc ready use pageinit of jQuerymobile if developing for mobile apps.

    0 讨论(0)
  • 2021-01-28 04:34

    When working with mobile devices, it is greatly recommended that you use the mobile version of jquery, jquery.mobile.js

    Then you can use vclick and everything works fine:

    Normalized event for handling touchend or mouse click events on touch devices.

    $(document).ready(function(){
         $("#btn1").vclick(function(){
           $("#test1").text("Hello world!");
         });
    });
    
    0 讨论(0)
  • 2021-01-28 04:35

    I don't think that JQuery is being loaded into the page.

    You have referenced it as

    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js">
    

    which says use whatever protocol the current page is being server from. On a mobile device you are being served from file:// so the actual request the browser makes to fetch the script is:

    file://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js
    

    You need to specify the scheme you want to use or else include it in the PG project itself.

    0 讨论(0)
提交回复
热议问题