- Url
- String manipulation
- Array and object manipulation
- Test actions
- Browser
1:url Action:
$.param (obj)
Back: string;
Description: The jquery object is serialized as a URL parameter by Name/value or Key/value, with a & connection.
Example:
var obj ={name:zh,age:20};
Alert (Jquery.param (obj));
Alert "name=zh&age=20";
2: String manipulation:
Jquery.trim (str)
Back: string;
Description: Remove the string and end space.
Example:
Alert ($.trim ("123"));
Alert "123";
3: Array and Object operations:
(1):
&.each (Obj,callback)
Description
A universal example method, which can be used for example objects and arrays.
Unlike the $ (). each () method of the JQuery object, this method can be used to sample any object.
The callback function has two parameters: the first is the index of the member or array of the object, and the second is the corresponding variable or content.
If you need to exit each loop so that the callback function returns false, the other return values are ignored.
Example:
var a =[0,1,2,3,4,5];
$.each (A,function (i,n) {document.write ("" +i+ "and" +n + "<br/>");});
Result
/*0 and 0
1 and 1
2 and 2
3 and 3
4 and 4
5 and 5i*/
(2):
$.extend (obj,default,option)
Description
This function function is most commonly used to handle options when developing plug-ins.
Here is the code for the FancyBox plug-in to get options:
Settings = $.extend ({}, $.fn.fancybox.defaults, settings);
The above code target is an empty object, defaults the default setting as the first object, merging the settings passed in by the user setting to default, and setting the properties on the setting. Setting no properties passed in, default defaults are used. The merged results are then copied to target and returned as function return values.
Look at a complete example:
var empty = {}
var defaults = {Validate:false, limit:5, Name: "foo"};
var options = {validate:true, name: "Bar"};
var settings = jquery.extend (empty, defaults, options);
/*result:
Settings = = {Validate:true, limit:5, Name: "Bar"}
empty = = {Validate:true, limit:5, Name: "Bar"}*/
The target parameter passes an empty object because the value of target is eventually changed. For example:
var defaults = {Validate:false, limit:5, Name: "foo"};
var options = {validate:true, name: "Bar"};
var settings = jquery.extend (defaults, options);
The above code takes defaults as the target parameter, although the result of the last settings is the same, but the value of the defaults is changed! and the default values in the plugin should all be fixed! Note the use of the target parameter when using.
(3): Screening
Jquery.grep (Array, callback, [invert])
return value: Array
Description
Filter the array elements using the filter function.
This function passes at least two parameters: the array to be filtered and the filter function. The filter function must return true to preserve the element or false to delete the element.
Explain:
The default invert is false, that is, the filter function returns true as a reserved element. If the set invert is true, the filter function returns true to delete the element.
The following example shows how to filter an element with an index less than 0 in the array:
$.grep ([0,1,2], function (n,i) {return
n > 0;
});
results:[1,2]
(4). Conversion
Jquery.map (Array, callback)
return Value: Array
Description
Converts an element in an array to another array.
The conversion function as a parameter is invoked for each array element, and the transformation function is passed a parameter that represents the converted element.
A conversion function can return a converted value, null (delete an item from an array), or an array containing values, and extend to the original array.
Example:
var arr = ["A", "B", "C", "D", "E"];
$ ("div"). Text (Arr.join (","));
arr = Jquery.map (arr, function (n, i) {return (N.touppercase () + i);});
$ ("P"). Text (Arr.join (","));
arr = Jquery.map (arr, function (a) {return a + A;});
Alert (Arr.join (","));
Alert a0a0, B1B1, C2C2, D3D3, e4e4
(5)
Jquery.makearray (obj), jquery.inarray (value, array) ,jquery.merge (i, second) ,
jquery.unique (Array) is no longer introduced,
It is also important to have JavaScript join () and Split () methods.
4: Test actions:
(1):
$.isfunction (FN)
return: Boolean;
Description: Test is a function;
Example:
VAR fn =function () {};
Alert ($.isfunction (FN));
Alert true;
(2):
$.isarray (obj);
return: Boolean;
Description: Test whether the array:
Example: slightly;
(3):
JavaScript only takes isNaN () and Isfinite (): Non-numeric and Infinity;
5: Browser object:
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 |
1.3 After the new version |
Jquery.browser |
has been abolished |
JQuery.browser.version |
has been abolished |
Jquery.boxmodel |
has been abolished |
$.support:
JQuery 1.3 is 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://www.jibbering.com/faq/faq_notes/not_browser_detect.html
Jquery.support mainly includes the following tests:
Boxmodel: This is true if the page and browser are rendered with the Web-browsers CSS box 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 you use Cssfloat to access the values of the float of 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: If the browser serializes the link elements by innerhtml them, returns True, and the current IE returns FALSE.
Leadingwhitespace: Returns True if the browser retains leading white-space characters while using innerHTML, and now returns false in IE 6-8.
nocloneevent: If the browser does not replicate with the event handler when cloning elements, returns true 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: If the browser can properly interpret the transparency style attribute, returns True and is currently returning false in IE because he replaces it with an alpha filter.
scripteval: When using the Appendchild/createtextnode method to insert script code, the browser executes the footstep, and now returns False,ie in IE using the. Text method to insert the script code to execute.
style: True if GetAttribute ("style") returns the inline style of the element. The current IE is false because he replaces it with Csstext.
tbody: Returns True if the browser allows the table element to contain no tbody elements. Currently in IE will return false, he will automatically insert the missing tbody.