从谷歌加载jquery不工作(对我来说)

Loading jquery from google doesn't work (for me)

本文关键字:对我来说 工作 谷歌 加载 jquery      更新时间:2023-09-26

啊,我是一个可怜的新手,下面的html文档并没有提醒任何人我的求助。有人知道为什么吗?

<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标签中。

Edit:实际上,如果在非本地上下文中加载页面,原始语法将正常工作。省略协议意味着将使用"当前"协议,这取决于资源是通过http还是https加载的。在本地加载它意味着脚本是从file:///ajax.googleapis.com/....加载的,这显然不会解析为任何内容。更多信息请看这里。

相同的语法在HTML5样板中使用:

<!-- Grab Google CDN's jQuery, with a protocol relative URL; fall back to local if necessary -->
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.js"></script>
<script>window.jQuery || document.write("<script src='js/libs/jquery-1.5.2.min.js'>'x3C/script>")</script>

http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js

//ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js

您在<script>标签的src属性的url前面缺少一个http::

<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="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"

Src属性的可能值为

绝对URL -指向另一个网站(如src="http://www.example.com/example.js")•相对URL -指向网站内的文件(如src="/scripts/example.js") 所以你的URL应该是http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js