简体   繁体   English

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

[英]html reference to jquery library + external file

I am wondering how to reference jquery in html . 我想知道如何在html引用jquery

To my understanding there has to be 2 links: 据我了解,必须有2个链接:

  1. To the library 去图书馆
  2. To the external file. 到外部文件。

here is my reference that does not seem to work.. 这是我的参考,似乎无效。

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

ps. PS。 1st time here, I know the question sounds stupid, I'm just going crazy with that 第一次来这里,我知道这个问题听起来很愚蠢,我只是为此而发疯

You only need one reference. 您只需要一个参考。 Let's say your folder structure is like this: 假设您的文件夹结构是这样的:

my_project/
    index.html
    jquery.js

Then in your index.html you just need to do this: 然后在index.html中,您只需要执行以下操作:

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

To include the JS file. 包含JS文件。 If however you don't have jquery.js there, and you want to reference it from a CDN (content delivery network). 但是,如果那里没有jquery.js,则想从CDN(内容交付网络)中引用它。 You could do something like this: 您可以执行以下操作:

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

It's good practice to use a CDN, or content delivery network, as the host for jQuery and other similar libraries. 最好使用CDN或内容交付网络作为jQuery和其他类似库的宿主。 This article does a good job of explaining the benefits. 本文很好地解释了好处。 One example of a quality, free CDN is Google . 高质量的免费CDN的一个例子是Google Here's how you would include Google's version of jQuery 2.1.3: 这是您包括Google版本的jQuery 2.1.3的方法:

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

link from file 文件链接

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

link from source 源链接

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

internal script 内部脚本

<script> // javascript here </script>

1 to the library: <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> 1进入库: <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>

2 to the external js file: <script type="text/javascript" src="/js/pinkmoon.js"></script> , assuming that js file is in the same folder as index.html 2到外部js文件: <script type="text/javascript" src="/js/pinkmoon.js"></script> ,假设js文件与index.html位于同一文件夹中

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM