I. Summary
This series of articles will take you into the wonderful world of jquery, with many authors ' specific experiences and solutions, even if you can use jquery to find some cheats in your reading.
We often use scripting to handle a variety of business logic, the most common being arrays and object operations, and the jquery tool function provides a convenient condition for manipulating objects and arrays.
Two. Foreword
Most people use jquery selectors only to select objects, or to animate the page, and to write many of their own algorithms when dealing with business logic, and this article reminds you that jquery can also improve the efficiency of our operations and arrays, and we can extend some common algorithms into jquery tool functions, Implements the reuse of script functions.
Three. What is a tool function
A tool function is a function defined on a jquery object (the variable "$"), which is a tool class function. For example, the most commonly used trim () function in C #:
$.trim ("");
There is no trim function in the original JavaScript that removes both before and after spaces. So this kind of commonly used tool function is called "Utilities" function. Corresponding to the jquery Official document:
Http://docs.jquery.com/Utilities
"$" is actually a property of the "Window" object, so the following sentences are equivalent:
$.trim ("");
Window.$.trim ("");
Window.jquery ("");
Jquery.trim ("");
Four. Tool function classification
Tool functions are mainly divided into the following categories:
- Browser and feature detection
- Array and object manipulation
- Test actions
- String manipulation
- URL Action
Different from the previous chapters, this article does not enumerate the list of functions. In applications, such as encountering a string to manipulate, you can first find out whether a quick tool function has been provided from the API document/utilities/string Operation . If no longer consider yourself developing.
The following is a common tool function that is used in each category of the instance specific.
Five. browser and feature detection
The best of jquery is its cross-browser features, and usually we don't have to write different code for different browsers. But if it's a jquery developer or plug-in developer, it's up to you to handle browser differences to provide users with cross-browser features.
jquery provides the following properties for obtaining browser attributes:
Jquery.support |
Version 1.3 new |
| Jquery.browser |
has been abolished |
JQuery.browser.version |
has been abolished |
| Jquery.boxmodel |
has been abolished |
Three attributes have been abolished in version 1.3 and are not explained here. Let's focus on the jquery.support function.
jquery.support return value: Object
Description:
JQuery 1.3 new. A set of properties that show the characteristics and bugs of different browsers.
jquery provides a range of attributes, and you can also freely add your own attributes. Many of these properties are low-level, so it's hard to say whether they can be kept valid for ever-changing developments, but these are mainly for plug-ins and kernel developers.
All of these supported property values are implemented through attribute detection, rather than any browser detection. Here are some great resources to explain how these feature detections work:
- http://peter.michaux.ca/articles/ Feature-detection-state-of-the-art-browser-scripting
- http://yura.thinkweb2.com/cft/
- http:// The www.jibbering.com/faq/faq_notes/not_browser_detect.html
Jquery.support mainly includes the following tests:
Boxmodel : True if this page and browser are rendered with the Web-view CSS cartridge model. This value is usually false in the quirks mode of IE 6 and IE 7. This value is null until the document is ready.
cssfloat : Returns True if Cssfloat is used to access the value of float in the CSS. Currently in IE will return false, he replaced with stylefloat.
hrefnormalized : Returns True if the browser returns an intact result from getattribute ("href"). Returns false in IE because his URLs are already conventionally made.
htmlserialize : Returns True if the browser serializes a LINK element by innerHTML it, and returns false in IE at the current time.
leadingwhitespace : Returns True if the browser retains leading white-space characters when using innerHTML, and now returns false in IE 6-8.
nocloneevent : Returns True if the browser does not replicate with the event handler when the element is cloned, and is currently returning false in IE.
Objectall : True if getElementsByTagName ("*") on an Element object returns all descendant elements, and is currently false in IE 7.
Opacity : Returns True if the browser can properly interpret the transparency style property, and is currently returning false in IE because he replaces it with an alpha filter.
scripteval : When inserting script code using the Appendchild/createtextnode method, the browser executes the script and is currently returned in IE using the false,ie. Text Method inserts script code to execute.
Style : True if GetAttribute ("style") returns the inline style of an element. The current IE is false because he replaces it with Csstext.
tbody : Returns True if the browser allows the table element to not contain tbody elements. Currently in IE will return false, he will automatically insert the missing tbody.