Chapter One understanding jqueryfirst, the Common JS library
- Prototype one of the earliest JS libraries. The use of JS method combination, the shortcomings of the structure of loose.
- Dojo offline storage API, generate icon component, Vector graphics library, comet support. Enterprise-Class JS library, the shortcomings of the document is not complete, the API is not stable.
- YUI Yahoo developed the rich interactive Web program toolset.
- Exit JS focus on the interface
- MooTools Lightweight JS framework for modular Thinking
- JQuery lightweight, powerful selectors, and more.
ii. Advantages of jquery
- Lightweight 30K or so
- Powerful Selector
- Excellent DOM encapsulation
- Reliable event-handling mechanism
- Ajax Perfect
- Non-polluting top-level variables
- Browser compatible
- Chained calls
- Implicit iteration
- Behavioral structure Separation
- Rich Plugins
- Document Perfection
- Open source
third, the preparation of matters of note
Chaining calls should be noted:
- No more than 3 operations for the same object, write directly as one line
- More operations on the same object, one action per line
- A small number of operations for multiple objects, one line per object (Indent child elements)
Iv. jquery objects and Dom objects
Dom objects are objects that are obtained directly from the DOM tree, and can be used with the JS method and not by the jquery method . jquery objects are the DOM objects that are wrapped in jquery, and you can use the JQuery method , and you cannot use the JS method (the variables obtained by the JQuery object are preceded by $ to differentiate).
The two convert each other:
- The jquery object is converted to a DOM object:
- [index] var dom=$ ("div") [0];
- Get (Index) var dom=$ ("div"). Get (0);
- The DOM object is converted to a jquery object: You can use $ () to package the DOM object directly.
v. jquery and other JS Libraries conflict resolution ($ transfer problem)
For jquery, global variables are stored in their own namespaces and generally do not conflict with other libraries
- jquery libraries are introduced after other libraries
- Jquery.noconflict (); Give variable $ control to other libraries
JQuery (function () {//using Jqery
Writing jquery programs;
})
2. Var $j =jquery.noconflict (); Customizing a shortcut
$j (function () {//Use Jqery, use a custom shortcut--$j
Writing jquery programs;
})
If you do not want to customize you also want to use $ (), regardless of the other library $ () method, and do not want to conflict with other libraries. Use:
- Jquery.noconflict (); Give variable $ control to other libraries
JQuery (function ($) {//Use Jqery to set the letter executed when the page is loaded, continue using $ () inside the function
Writing jquery programs;
})
- Jquery.noconflict (); Give variable $ control to other libraries
(function ($) {///define an anonymous function and set the parameter to $, the inside of the anonymous function is Jqery, continue using $ () inside the function
$ (function () {
Writing jquery programs;
})
}) (JQuery);
- jquery Library introduced in front of other libraries
Without calling Jquery.noconflict (), using jquery directly for jquery, the other libraries use $ ().
"Sharp jquery" study notes 01