为什么Google Developer Library的jQuery链接中没有协议? [英] Why there isn't a protocol in Google Developer Library's jQuery link?

查看:58
本文介绍了为什么Google Developer Library的jQuery链接中没有协议?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我总是有疑问.我认为Google很聪明. 但是当我复制那里的开发人员站点的jquery链接时 https://developers.google.com/speed/libraries/devguide 以下jquery链接

I am always in doubt. I consider that google is intelligent . But when i copy the jquery link for there developer site https://developers.google.com/speed/libraries/devguide the following jquery link

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>

示例代码

<html>
    <head>
        <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
        <script type='text/javascript'>
          $(document).ready(function(){
            alert('hello');
          });
        </script>
    </head>
    <body>
    </body>
</html>

这对我不起作用

但是当我用

<html>
    <head>
        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
        <script type='text/javascript'>
          $(document).ready(function(){
            alert('hello');
          });
        </script>
    </head>
    <body>
    </body>
</html>

对我有用

为什么Google没有在链接中附加http:?这是故意的吗?

Why has google not appended http: in the link? is it deliberate?

我正在使用mozilla作为浏览器

I am using mozilla as browser

推荐答案

Google选择不使用该协议,以便其片段可以通过继承当前协议而在httphttps页面上正常工作.

Google chose to leave out the protocol so that its snippet can work across both http and https pages by inheriting the current protocol.

编辑

如果使用浏览器打开html文件,则默认协议为file://,这就是为什么它不起作用的原因.您必须将文件托管在Web服务器中,才能使其与//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js网址一起使用.

If you are opening the html file with your browser, the default protocol is file:// so that's why it won't work. You will have to host the file inside a web server to make it work with the //ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js url.

这篇关于为什么Google Developer Library的jQuery链接中没有协议?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆