从谷歌加载jquery不起作用(对我来说) [英] Loading jquery from google doesn't work (for me)
问题描述
啊,我是一个可怜的菜鸟,下面的html文件并没有提醒我的任何人请求帮助。有谁知道为什么?
Ah the wretched noob I am, the following html document doesn't alert anyone of my cry for help. Anyone know why?
<html>
<head>
<script type="text/javascript"
src="//ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
alert('Somebody please help me.');
});
</script>
</head>
<body>
</body>
</html>
推荐答案
这对我有用:
<html>
<head>
<script type="text/javascript"
src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
alert('Somebody please help me.');
});
</script>
</head>
<body>
</body>
</html>
修复 src
中的 script
tag。
编辑:实际上,如果你加载了原始语法,它将正常工作非本地环境中的页面。省略协议意味着将使用当前协议,具体取决于是否通过 http
或 https
加载资源。在本地加载意味着该脚本是从 file:/// ajax.googleapis.com / ....
加载的,显然无法解析为任何内容。有关详细信息,请参见此处。感谢@PetrolMan指向HTML 5样板站点。
Actually, the original syntax would work fine if you load the page in a non-local context. Leaving out the protocol implies that the 'current' protocol would be used depending on whether resources are loaded over http
or https
. Loading it locally implies that the script is loaded from file:///ajax.googleapis.com/....
, which obviously won't resolve to anything. See here for more information. Thanks to @PetrolMan for pointing to the HTML 5 boiler plate site.
这篇关于从谷歌加载jquery不起作用(对我来说)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!