jQuery UI $.datepicker () 对于 Google Code CDN 不存在(本地工作)
当我在我的 : ... 和我的脚本 $(document).ready ()
中使用以下代码链接到存储在 Google 服务器上的 jQuery UI 文件时,
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.min.js"></script>
我执行以下操作...
$("#date-processed").datepicker ({ dateFormat: 'M. dd, yy' });
脚本此页面上的所有浏览器都会中断。原因是它说“datepicker”不作为函数存在。因此,如果我访问 http://jqueryui.com/download 并下载带有 UI Core 的自定义 jQuery UI 库和 Datepicker 并在 my 中链接该文件,它工作得很好。
因此,为了进行实验,我从 http://jqueryui.com/download 下载了自定义 jQuery UI 库 一切都检查过了,然后我 Google 的 jQuery UI 的 CDN 副本,文件大小有 7kb 差异。
在我见过的大多数 Datepicker 教程和示例中,人们都很好地使用 Google 的 CDN 副本,因此我认为这一定是我做错了,而不是 Google 方面的不一致。我已经验证了我本地的jQuery UI版本号和Google的CDN版本号是相同的。任何熟悉 Google 的 CDN 和 jQuery UI 的人都可以解释一下这种情况吗?
When I link to the jQuery UI file stored on Google's servers with the following code in my :
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.min.js"></script>
... and in my scripts $(document).ready ()
I do the following ...
$("#date-processed").datepicker ({ dateFormat: 'M. dd, yy' });
The script will break for all browsers on this page. The reason being it says "datepicker" does not exist as a function. So, if I go to http://jqueryui.com/download and download the custom jQuery UI library with UI Core and Datepicker and link that file in my instead, it works just fine.
So, to experiment, I downloaded the custom jQuery UI library from http://jqueryui.com/download with everything checked, then I Google's CDN copy of jQuery UI, and there's a 7kb difference in the file sizes.
In most of the Datepicker tutorials and examples I've seen, people are using Google's CDN copy just fine, so I assume this must be something I'm doing incorrectly, not an inconsistency on Google's part. I have verified my local version number and Google's CDN version number of jQuery UI are the same. Anyone familiar enough with Google's CDN and jQuery UI to shed some light on this situation?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Qorbani 要求我使用 JSFiddle 发布源代码,所以我尝试了一下,发现当我使用 JSFiddle 时它可以工作(http://jsfiddle.net/Znjvh/3/)。然后我意识到问题是在页面上我还使用了 jQuery 工具并将其包含在 jQuery UI 之后。当我将它移到 jQuery UI 之上时,一切正常(http://jsfiddle.net/Znjvh/5/)。
我去寻找 jQuery UI 和 jQuery Tools 之间的冲突,发现我使用的 jQuery Tools 的标准 URL http://cdn.jquerytools.org/1.2.6/jquery.tools.min.js,还包括 jQuery。这很可能就是冲突所在(尽管可能还有更多冲突。例如,正如“mu 太短”指出的那样,jQuery 工具和 jQuery UI 都使用
.tabs()
)。无论如何,对于偶然发现这个问题的其他用户,如果您同时使用 jQuery 工具和 jQuery UI,请确保您包含的 jQuery 工具不也包含 jQuery。我通过将 URL 更改为 http://cdn.jquerytools 来修复它.org/1.2.6/tiny/jquery.tools.min.js (http://jsfiddle.net/Znjvh/6/)。
谢谢你们的帮助,伙计们!
Qorbani requested I use JSFiddle to post the source code, so I played around with that and found that it worked when I used JSFiddle (http://jsfiddle.net/Znjvh/3/). I then realized the issue was that on the page I was also using jQuery Tools and including it after jQuery UI. When I moved it above jQuery UI, everything worked fine (http://jsfiddle.net/Znjvh/5/).
I went to hunt down the conflict between jQuery UI and jQuery Tools and found that the standard URL for jQuery Tools that I was using, http://cdn.jquerytools.org/1.2.6/jquery.tools.min.js, also includes jQuery. That's likely where the conflict was (though there could have been more. As "mu is too short" pointed out, both jQuery Tools and jQuery UI use
.tabs()
, for instance).Anyway, for other users that stumble upon this question, if you are using jQuery Tools and jQuery UI together, make sure you are including the jQuery Tools that does not also include jQuery. I fixed it by changing the URL to http://cdn.jquerytools.org/1.2.6/tiny/jquery.tools.min.js (http://jsfiddle.net/Znjvh/6/).
Thanks for your help, guys!