Ajax Jquery的疑惑 [英] Ajax Jquery doubts

查看:293
本文介绍了Ajax Jquery的疑惑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么我们必须将 jquery.mn.js (某些文件)添加到SCRIPT标签..,以及表单验证和其他一些jquery和ajax程序。



我们可以在哪里下载该文件,以及在PC中保存该文件的位置。

解决方案

如果没有在您的页面上引用库(通常位于< head> 标签)中,jQuery代码将无法正常工作。 另外,还有一些其他的库,它们构建在jQuery库之上,比如Twitter的优秀的 getbootstrap.com/getting-started/rel =nofollow>引导程序库 jQueryUI 。在这些情况下,您需要 jQuery库附加库 - 如下面第一个示例中针对jQueryUI所示。



在页面中包含jQuery库有几个选项。



CDN(内容分发网络)是在线存储位置,网页可以抓取指定的代码,而不需要将其存储在服务器上。 这就是为什么CDN是好的想法



一:1.使用CDN:

 < HEAD> 
< script src =// ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js\"> ;</script>
< script src =// ajax.googleapis.com/ajax/libs/jqueryui/1.9.1/jquery-ui.min.js\"> ;</script>
< link rel =stylesheethref =http://code.jquery.com/ui/1.9.1/themes/base/jquery-ui.css/>
< / head>

二:2.下载jQuery脚本:




  • 去这里: http://jquery.com/download/

  • 点击您想要的版本

  • 当您在浏览器中看到代码时,将其保存到文本文件中

  • 将jquery.js文件存储在webroot(通常是 public_html )中是最简单的,但您可以将其存储在任何地方(并将其命名为任何您想要的内容 - 当您在< script> 标记中引用它时,您只需使用相同的名称/位置。

  • 存储在一个名为 js
  • 的子目录中。
  • 将其包含在头标记中,即:




三:3.上述组合,后备

 < script src =// ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js type =text / javascript>< / script> 
& LT;脚本> window.jQuery || document.write('< script src =../ js / jquery-1.10.2.min.js>< \ / script>')< / script>

上面的代码是这样的:

一个。从CDN中加载jQuery库
b。如果CDN没有加载,请从指定位置加载jQuery服务器(请注意,jQuery库也必须位于您的服务器上,位于指定位置)。



注意: b
$ b


  • 有两种形式的jquery.js您可以使用的代码:缩小和常规。区别在于缩小的代码加载速度更快,但常规的代码是人类可读的。使用你想要的任何一个。如果您决定为了自己的目的自定义jQuery库,您需要编辑可读的jQuery库。


Why we have to add jquery.mn.js (some file ) to the SCRIPT tag.., in form validation and some other jquery and ajax programs..

Where we can download that file., and where have to SAVE that file in PC.

解决方案

jQuery code will not work without the library being referenced on your page (usually in the <head> tags).

Also, there are some other libraries that build on top of the jQuery library, like Twitter's excellent bootstrap library, or jQueryUI. In those cases, you need both the jQuery library and the additional library -- as shown for jQueryUI in the first example below.

There are a few options for including jQuery libraries on your page.

CDNs (Content Delivery Networks) are online storage locations where web pages can grab the specified code, without you needing to store it on your server. This is why a CDN is a good idea.

One: 1. Use a CDN:

<head>
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
    <script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.9.1/jquery-ui.min.js"></script>
    <link rel="stylesheet" href="http://code.jquery.com/ui/1.9.1/themes/base/jquery-ui.css" />
</head>

Two: 2. Download the jQuery script:

  • Go here: http://jquery.com/download/
  • Click on the version you want
  • When you see the code in your browser, save that into a text file
  • It is simplest to just store the jquery.js file in your webroot (usually public_html), but you can store it anywhere (and name it anything you want -- you just have to use the same name/location when you reference it in your <script> tag.
  • Below example has it stored in a subdir called js
  • Include it in your head tags, thus:

Three: 3. A combination of the above, with fallback

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

The above code does this:

a. Load the jQuery library from the CDN
b. IF the CDN did not load, then load the jQuery from the specified location on my server (Note that the jQuery library must also be available on your server, at the location specified).

Notes:

  • There are two forms of the jquery.js code that you can use: minified and regular. The difference is that the minified code loads faster, but the regular code code is human-readable. Use whichever one you wish. If you decide to customize the jQuery library for your own purposes some day, you will want to edit the human-readable one.

这篇关于Ajax Jquery的疑惑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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