jQuery介绍
write less ,do more :Lightweight Footprint、CSS3 Compliant、Cross-Browser
What is jQuery?
- jQuery is a fast, small, and feature-rich JavaScript library. It makes things like HTML document traversal and manipulation, event handling, animation, and Ajax much simpler with an easy-to-use API that works across a multitude of browsers. With a combination of versatility and extensibility, jQuery has changed the way that millions of people write JavaScript.
define:
- jQuery is a cross-platform JavaScript library designed to simplify the client-side scripting of HTML.
- jQuery is free, open source software, licensed under the MIT License.
- jQuery‘s syntax is designed to make it easier to navigate a document, select DOM elements, createanimations, handle events, and develop Ajax applications. jQuery also provides capabilities for developers to create plug-ins on top of the JavaScript library. This enables developers to create abstractions for low-level interaction and animation, advanced effects and high-level, theme-able widgets. The modular approach to the jQuery library allows the creation of powerful dynamic web pages and web applications.
overviw:
- jQuery, at its core, is a DOM manipulation library. The DOM is a tree structure representation of all the elements of a web-page and jQuery makes finding, selecting, and manipulating these DOM elements very simple and convenient. For example, jQuery can be used for finding an element in the document with a certain property (e.g. all elements with an h1 tag), changing one or more of its attributes (e.g. color, visibility), or making it respond to an event (e.g. a mouse click).
- However, beyond basic DOM selecting and manipulation, jQuery provides a new paradigm of writing event handling in Javascript. The event assignment and the event callback function are done in a single step in a single location in the code.
The advantages of using jQuery are:
- Separates Javascript and HTML: Instead of using HTML attributes to call Javascript functions for event handling, jQuery allows all event-handling functions to be done purely in Javascript. Thus, the HTML tags and Javascript can be completely separated.
- Brevity and Clarity: jQuery provides various syntaxes that promotes brevity and clarity, e.g. chaining effects and actions, shorthand methods.
- Eliminates cross-browser incompatibilities: The Javascript engines of different browsers differ slightly, so Javascript code that works for one browser may not work on the other. jQuery handles all these cross-browser inconsistencies and provides a consistent interface that works across different browsers.
jQuery includes the following features:
- DOM element selections using the multi-browser open source selector engine Sizzle, a spin-off of the jQuery project
- DOM traversal and modification (including support for CSS 1–3)
- DOM manipulation based on CSS selectors that uses node elements name and node elements attributes (id and class) as criteria to build selectors
- Events
- Effects and animations
- AJAX
- JSON parsing
- Extensibility through plug-ins
- Utilities - such as user agent information, feature detection
- Compatibility methods that are natively available in modern browsers but need fall backs for older ones - For example the
inArray()
andeach()
functions. - Multi-browser (not to be confused with cross-browser) support.
- multitude browsers support
什么是jQuery?
- Jquery是继prototype之后又一个优秀的Javascript框架。它是轻量级的js库 ,它兼容CSS3,还兼容各种浏览器(IE 6.0+, FF 1.5+, Safari 2.0+, Opera 9.0+),jQuery2.0及后续版本将不再支持IE6/7/8浏览器。jQuery使用户能更方便地处理HTML(标准通用标记语言下的一个应用)、events、实现动画效果,并且方便地为网站提供AJAX交互。jQuery还有一个比较大的优势是,它的文档说明很全,而且各种应用也说得很详细,同时还有许多成熟的插件可供选择。jQuery能够使用户的html页面保持代码和html内容分离,也就是说,不用再在html里面插入一堆js来调用命令了,只需定义id即可。
- jQuery是免费、开源的,使用MIT许可协议。jQuery的语法设计可以使开发者更加便捷,例如操作文档对象、选择DOM元素、制作动画效果、事件处理、使用Ajax以及其他功能。除此以外,jQuery提供API让开发者编写插件。其模块化的使用方式使开发者可以很轻松的开发出功能强大的静态或动态网页。
使用方法:
- jQuery可以下载使用,有两个版本的 jQuery 可供下载
- Production version - 用于实际的网站中,已被精简和压缩。
- Development version - 用于测试和开发(未压缩,是可读的代码)
- 也可以从多个公共服务器中选择引用。把jQuery存储在CDN公共库上可加快网站载入速度,(CDN公共库是指将常用的JS库存放在CDN节点,以方便广大开发者直接调用)。
-
1 Google CDN: 2 <scripttype="text/javascript"src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script> 3 Microsoft CDN: 4 <scripttype="text/javascript"src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-2.1.0.min.js"></script> 5 新浪 CDN: 6 <scripttype="text/javascript"src="http://libs.baidu.com/jquery/2.0.3/jquery.min.js"></script> 7 百度 CDN: 8 <scripttype="text/javascript"src="http://libs.baidu.com/jquery/2.0.3/jquery.min.js"></script> 9 使用本地jQuery: 10 <scripttype="text/javascript">window.jQuery||document.write(‘<scriptsrc="//localhost/jQuery/jquery-2.1.0.min.js"><\/script>‘);</script> 11 Wordpress主题中使用: 12 <scripttype="text/javascript">window.jQuery||document.write(‘<scripttype="text/javascript"src="<?phpechoget_template_directory_uri();?>/jquery.min.js">\x3C/script>‘)</script>
W3SCHOOL:(详细学习请移步于此)
jQuery 是一个 JavaScript 函数库。jQuery 库可以通过一行简单的标记被添加到网页中。
jQuery 库包含以下特性:
- HTML 元素选取
- HTML 元素操作
- CSS 操作
- HTML 事件函数
- JavaScript 特效和动画
- HTML DOM 遍历和修改
- AJAX
- Utilities
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。