最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Use jQuery in HTML - Stack Overflow

programmeradmin2浏览0评论

In order to use jQuery, do I have to use the following reference in my html?

 <script src=".5/jquery.min.js"></script>

What if my server does not have an internet connection?

In order to use jQuery, do I have to use the following reference in my html?

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

What if my server does not have an internet connection?

Share Improve this question edited May 24, 2013 at 20:46 Matthew Strawbridge 20.6k10 gold badges79 silver badges96 bronze badges asked Feb 23, 2012 at 14:29 george willygeorge willy 1,7138 gold badges22 silver badges26 bronze badges 5
  • 1 what if my server does not have an internet connection? How are you connecting to it if it doesn't have a internet connection? And besides, it's the client which requests that file from the Google CDN, not the server. – Rory McCrossan Commented Feb 23, 2012 at 14:31
  • 3 @RoryMcCrossan: localhost, I'd imagine. – Ry- Commented Feb 23, 2012 at 14:32
  • 2 Rory, not acquainted with a thing we like to call local testing? ;) – Flater Commented Feb 23, 2012 at 14:32
  • @minitech damn you with your logic. And you Flater. – Rory McCrossan Commented Feb 23, 2012 at 14:33
  • @mike smith, I've edited second part of your question, because it isn't different question. Ask a new question for it if you want. – Chuck Norris Commented Feb 23, 2012 at 14:59
Add a comment  | 

5 Answers 5

Reset to default 9

Use this code:

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">window.jQuery || document.write('<script src="/res/jQuery/jquery-1.7.1.min.js"> \x3C/script>');</script>

This will try to download from the CDN, or otherwise use the local one. You must download the local one first though.

It will not work if you don't have internet connection. To work locally you should copy jquery.js to your local directory and give relative path.

 <script src="/jquery/1.5/jquery.min.js"></script>

It is not specifically for this case, but I think you should definitely understand how Client-server works. Also, you should understand what is Client-side scripting.

You would then understand that you (your browser) need to be connected to Internet in order to be able to reach the http://ajax.googleapis.com domain.

If you want to work with it locally, without ever reaching Internet, then download jQuery locally, and refer to it in your script tag.

Download the latest jquery file:

http://code.jquery.com/jquery-1.7.1.min.js

And save it to you project. It will now be available locally so you can reference it like this (only an example):

 <script src="/path-to-your-jquery-file.js"></script>

It does not matter if your server has or has not connection to internet. Only the browser which tries to access page from said server need connection to internet. Server just needs to be "visible" from this browser in question.

It might be better, if you understood the basics of how internet works, before you start playing in developers.

发布评论

评论列表(0)

  1. 暂无评论