对 jquery 库 + 外部文件的 HTML 引用

html reference to jquery library + external file

本文关键字:HTML 引用 文件 外部 jquery      更新时间:2023-09-26

我想知道如何在html中引用jquery

据我了解,必须有 2 个链接:

  1. 前往图书馆
  2. 到外部文件。

这是我的参考,似乎不起作用。.

<script type="text/javascript" src="jquery.js" ></script>
<script src="jquery-2.1.3.js"></script>

第一次在这里,我知道这个问题听起来很愚蠢,我只是发疯了

你只需要一个引用。假设您的文件夹结构如下所示:

my_project/
    index.html
    jquery.js

然后在索引中.html您只需要执行以下操作:

<script type="text/javascript" src="jquery.js" ></script>

以包含 JS 文件。 但是,如果您没有jquery.js,并且您想从CDN(内容交付网络)引用它。你可以做这样的事情:

<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js" ></script>

最好使用 CDN 或内容交付网络作为 jQuery 和其他类似库的主机。本文很好地解释了好处。高质量、免费 CDN 的一个例子是谷歌。以下是您将如何包含Google版本的jQuery 2.1.3:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>

来自文件的链接

<script type="text/javascript" src="js/jquery.js"></script>

从源链接

<script type="text/javascript" src="http://thesource.com/jquery.js"></script>

内部脚本

<script> // javascript here </script>

1 到库:<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>

2 到外部 js 文件:<script type="text/javascript" src="/js/pinkmoon.js"></script>,假设 js 文件与索引位于同一文件夹中.html