2

我在标题中引用了以下 jquery 文件:

<link rel='stylesheet' href='$root/css/jquery.mobile-1.3.2.min.css'>

<script type='text/javascript' src='$root/js/jquery.mobile-1.3.2.min.js'>
</script>

<script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js'>
</script>

我收到以下错误:

a is undefined

该错误引用了整个 jquery.mobile-1.3.2.min.js 文件。

任何想法为什么会发生这种情况?

4

2 回答 2

4

脚本的顺序是错误的。 同时关闭link标签。

jQuery mobile 是在 jQuery 之后调用的。

这里是CDN-hosted files

<link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.css" />
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script src="http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.js"></script>

从你的角度来看:

<link rel='stylesheet' href='$root/css/jquery.mobile-1.3.2.min.css'/>
<script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js'>
</script>
<script type='text/javascript' src='$root/js/jquery.mobile-1.3.2.min.js'>
</script>
于 2013-08-22T04:59:36.543 回答
3

您必须先包含JQuery,然后再包含JQuery Mobile. 这是因为JQuery Mobile正在使用JQuery,当您JQuery Mobile首先包含时,它会寻找功能JQuery,在此阶段不会包含这些功能。

<link rel="stylesheet" href="http://code.jquery.com/mobile/1.2.1/jquery.mobile-1.2.1.min.css" />
<script src="http://code.jquery.com/jquery-1.8.3.min.js"></script>
<script src="http://code.jquery.com/mobile/1.2.1/jquery.mobile-1.2.1.min.js"></script>
于 2013-08-22T04:59:29.273 回答