将jQuery包含到html中 [英] include jQuery to html

查看:127
本文介绍了将jQuery包含到html中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 https://codepen.io/上使用jQuery,并且包含jQuery非常容易.因此,我决定在计算机上的文件上工作,我尝试使用该文件将其包括在内,但该文件无法正常工作.我也尝试从CDN收录,但还是行不通.

I was working with jQuery on https://codepen.io/ and to include jQuery is very easy. So i decided to work on files on my computer, i tried to include it using the file and it didn't work. also i tried to include from CDN but still doesn't work.

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

在Web.js中,我输入了以下代码:

and in the Web.js i put this code:

<button id="btn">Hide</button>
<p id="para">A dpara.</p>

推荐答案

您的Web.js不是javascript文件,而是HTML文件. 您要创建一个新的HTML文件,例如index.html. 您可以像这样填写此内容:

Your Web.js isn't a javascript file, but rather an HTML-file. You want to create a new HTML file named for example index.html. You fill this one up like so:

<!--  index.html: -->
<html>
  <head>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
    <script src="js/Web.js"></script>
  </head>
  <body>
    <button id="btn">Hide</button>
    <p id="para">A dpara.</p>
  </body>
</html>

您现在应该可以按照自己的意愿使用jQuery.

You should be able to use jQuery as you wish now.

此外,这是上面示例中应具有的文件夹结构:

Also, this is the folder structure you should have with the above example:

  • index.html
  • js
    • Web.js
    • index.html
    • js
      • Web.js

      这篇关于将jQuery包含到html中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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