简体   繁体   English

jQueryMobile无法在Android上随Phonegap一起加载

[英]jQueryMobile Does not load with Phonegap on Android

Regular javascript works, however when I try to use jQuery or jQueryMobile, it does not load. 常规javascript可以工作,但是当我尝试使用jQuery或jQueryMobile时,它不会加载。 I have downloaded the compressed jQueryMobile file, and placed it in my project. 我已经下载了压缩的jQueryMobile文件,并将其放置在我的项目中。

These are my script declarations in my HTML file 这些是我在HTML文件中的脚本声明

<script type = "text/javascript" src = "cordova-2.7.0.js"></script>
<script type = "text/javascript" src = "js/jquerymobile.js"></script>
<script type = "text/javascript" src = "js/myscript.js"></script>

This is the function in myscript.js that is not firing: 这是myscript.js中未触发的函数:

$(document).ready(function()
    {
        alert('at least this works');
    });

I can see in logcat this error message: 我可以在logcat中看到此错误消息:

06-06 14:57:19.555: D/CordovaLog(249): file:///android_asset/www/js/myscript.js: Line 15 : ReferenceError: Can't find variable: $

Which prompts me to believe that jQueryMobile isn't loading at all. 这促使我相信jQueryMobile根本没有加载。 The other solutions that I found regarding this error message did not work for me. 我找到的有关此错误消息的其他解决方案对我不起作用。 Any help will be appreciated. 任何帮助将不胜感激。

EDIT: 编辑:

I added jQuery and swapped out deviceready for pageinit. 我添加了jQuery,并将deviceready换成了pageinit。 I am still getting errors. 我仍然遇到错误。

My new script declarations are: 我的新脚本声明是:

<script type = "text/javascript" src = "cordova-2.7.0.js"></script>
<script type = "text/javascript" src = "js/jquery.js"></script>
<script type = "text/javascript" src = "js/jquerymobile.js"></script>
<script type = "text/javascript" src = "js/myscript.js"></script>

My new function that is not being called is: 我没有被调用的新函数是:

$(document).on('pageinit', function () 
    { 
        alert('at least this works');
    }); 

And Here are some interesting error messages from logcat: 这是来自logcat的一些有趣的错误消息:

06-06 15:16:39.777: D/CordovaLog(219): file:///android_asset/www/js/jquery.js: Line 3345 : TypeError: Result of expression 'Object.defineProperty' [undefined] is not a function.

06-06 15:16:40.747: D/CordovaLog(219): file:///android_asset/www/js/jquerymobile.js: Line 26 : TypeError: Result of expression '$' [undefined] is not an object.

06-06 15:16:40.757: D/CordovaLog(219): file:///android_asset/www/js/myscript.js: Line 15 : ReferenceError: Can't find variable: $

Downgrade your jQuery version from 2.0.2 to 1.9.1 or 1.8.3 将jQuery版本从2.0.2降级到1.9.11.8.3

jQuery Mobile is locked to certain jQuery versions and current jQuery Mobile 1.3.1 will work with jQuery 1.7 up to 1.9.3. jQuery Mobile已锁定到某些jQuery版本,当前的jQuery Mobile 1.3.1将与jQuery 1.7最高支持1.9.3.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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