未捕获的类型错误:无法将属性'mobile'设置为未定义的。

19

我正在使用 AngularJS 和 PhoneGap 开发一个应用程序。

我在指令中使用了 jQuery Mobile,它是用来为通知栏添加一些动画效果的。在使用 jQuery 1.8.1 时它运行良好,但当我使用 jQuery Mobile 时……


(Note: The original text was already in Chinese. I have simply translated it into a more natural-sounding version.)
<script src="scripts/vendor/jquery/jquery.mobile-1.3.1.js"></script>

我遇到了以下错误:

Uncaught TypeError: Cannot set property 'mobile' of undefined jquery.mobile-1.3.1.js:26

(anonymous function) jquery.mobile-1.3.1.js:26
(anonymous function) jquery.mobile-1.3.1.js:27
(anonymous function) jquery.mobile-1.3.1.js:22
(anonymous function) jquery.mobile-1.3.1.js:24

输入图片描述

有什么建议吗?

提前致谢!


你正在使用哪个版本的jQuery?对于jQuery-Mobile 1.3.1,建议使用jQuery 1.8.3及更高版本。 - Omar
1
@Omar,其实你的评论让我修复了这个问题。我将代码注释掉了:<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script> 谢谢! - Arcayne
3个回答

23

在使用 jQuery-Mobile 1.3.1 版本时,请使用 jQuery 1.8.3 版本或更高版本。建议使用 jQuery 1.9.1 版本


10
可能很明显,但却让我困扰了。在引入jQuery mobile之前,请先引入jQuery脚本,否则您将继续看到该错误,并且不知道出了什么问题。 - Josh
3
@Josh,确切地说,在加载jQuery Mobile之前应该先加载jQuery。此外,更改全局设置代码应该放在JQM之前。 - Omar
谢谢。节省了很多时间。 - Erdem Güngör

6

@Omar,实际上你的评论让我修复了这个问题,我把它注释掉了:

<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>

谢谢!


欢迎!我将其作为未来参考的答案添加了。 - Omar

2

先引入Jquery,然后再引入Jquery-mobile,如下:

    <script src="js/libs/jquery/jquery.js" type="text/javascript"></script>
    <script src="js/libs/jquery-mobile/jquery.mobile.js" type="text/javascript"></script>

另外,正如其他人所说,使用jQuery版本1.9.1或更高版本。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接