javascript - 代码不适用于 Phonegap 应用程序

标签 javascript android jquery jquery-mobile cordova

目前我正在研究 Phonegap,我找到了一个示例代码,我想让它适用于 Phonegap,但我做不到。 我还想提一下,这里使用的是 Jquery MObile 1.2.0,但我想使用 Jquery mobile 1.3.2 和 JQuery 2.1.1,cordova-3.4.0

任何帮助将不胜感激。提前致谢。

    <!DOCTYPE html>
<html>
    <head>
        <title>jQM Complex Demo</title>
        <meta name="viewport" content="initial-scale=1, maximum-scale=1"/>
        <link rel="stylesheet" href="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.css" />
        <style>
            #content {
                padding: 0;
                position : absolute !important;
                top : 40px !important; 
                right : 0;
                bottom : 40px !important; 
                left : 0 !important;    
            }
        </style>
        <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=true"></script>   
        <script src="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.js"></script>  
        <script>
        $(document).on('pageinit', '#index',function(e,data){   
           var minZoomLevel = 12;

           var map = new google.maps.Map(document.getElementById('map_canvas'), {
              zoom: minZoomLevel,
              center: new google.maps.LatLng(38.50, -90.50),
              mapTypeId: google.maps.MapTypeId.ROADMAP
           });
                });
        </script>
    </head>
    <body>
        <div data-role="page" id="index">
            <div data-theme="a" data-role="header">
                <h3>
                    First Page
                </h3>
            </div>

            <div data-role="content" id="content">
                <div id="map_canvas" style="height:100%"></div>
            </div>

            <div data-theme="a" data-role="footer" data-position="fixed">
                <h3>
                    First Page
                </h3>
            </div>
        </div>
    </body>
</html> 

最佳答案

此代码不起作用的原因是您缺少 jQuery 库。没有 jQuery,jQuery Mobile 就无法工作。

这就是您收到此错误的原因:

"Uncaught TypeError: Cannot read property 'mobile' of undefined", source: code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.js (2) AND on Android device screen I am getting "First Page" two times in vertical order but there is no map .

关于javascript - 代码不适用于 Phonegap 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24159715/

相关文章:

java - 通过 Microsoft Exchange 发送电子邮件

jquery - 如何在 ASP.NET 4 母版页中使用 jQuery

javascript - Vimeo 视频灯箱

javascript - 谷歌地图,addlistener 不工作

javascript - 如何注释返回状态片段的函数的流类型?

android - 如何在android中获取设备的基带版本?

android - 使用 android ndk - camera api 拍照

jquery - 在 JQuery Mobile 中两个不同文件的三个页面之间导航

javascript - 为什么我经常看到这个 Javascript 构造/约定? (即在它自己的行上创建 'var foo;',而不是通过赋值)

javascript - 在 Gradle 中自动化 Jasmine 测试