Jquery static method

Source: Internet
Author: User
JQuery. browser (safari, opera, msie, mozilla)
JQuery. browser. version
JQuery. boxModel
JQuery. each (object, callback)
JQuery. extend (target, object1, [objectN]) (modify value)
JQuery. grep (array, callback, [invert]) (excluded)
JQuery. makeArray (obj) (generate an array)
JQuery. map (array, callback) (custom processing array)
JQuery. inArray (value, array) (-1: Not found)
JQuery. unique (array) (deduplication)
JQuery. isFunction (obj) (whether it is a function)
JQuery. trim (str) (remove spaces)


1. User Agent

JQuery. browser (safari, opera, msie, mozilla)
$. Browser. msie
JQuery. each (jQuery. browser, function (I, val ){
$ ("<Div>" + I + ": <span>" + val + "</span> ")
. AppendTo (document. body );
});

JQuery. browser. version (version)
Internet Explorer: 6.0, 7.0
Mozilla/Firefox/Flock/Camino: 1.7.12, 1.8.1.3 and 1.9
Opera: 1, 9.20
Safari/Webkit: 312.8, 418.9

JQuery. boxModel (whether to use W3C Model)


2. Array and Object operations

JQuery. each (object, callback)
Var arr = ["one", "two", "three", "four", "five"];
Var obj = {one: 1, two: 2, three: 3, four: 4, five: 5 };

JQuery. each (arr, function (){
$ ("#" + This). text ("My id is" + this + ".");
Return (this! = "Four"); // will stop running to skip "five"
});

JQuery. each (obj, function (I, val ){
$ ("#" + I). append (document. createTextNode ("-" + val ));
});

JQuery. extend (target, object1, [objectN]) (modify value)
Var settings = {validate: false, limit: 5, name: "foo "};
Var options = {validate: true, name: "bar "};
JQuery. extend (settings, options );

JQuery. grep (array, callback, [invert]) (excluded)
Var arr = [1, 9, 3, 8, 6, 1, 5, 9, 4, 7, 3, 8, 6, 9, 1];
$ ("Div"). text (arr. join (","));

Arr = jQuery. grep (arr, function (n, I ){
Return (n! = 5 & I> 4 );
});
$ ("P"). text (arr. join (","));

Arr = jQuery. grep (arr, function (a) {return! = 9 ;});
$ ("Span"). text (arr. join (","));

JQuery. makeArray (obj) (generate an array)
Var arr = jQuery. makeArray (document. getElementsByTagName ("div "));
Arr. reverse (); // use an Array method on list of dom elements
$ (Arr). appendTo (document. body );

JQuery. map (array, callback) (custom processing array)
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 + ;});
$ ("Span"). text (arr. join (","));

JQuery. inArray (value, array) (-1: Not found)
Var arr = [4, "Pete", 8, "John"];

$ ("Span: eq (0)"). text (jQuery. inArray ("John", arr ));
$ ("Span: eq (1)"). text (jQuery. inArray (4, arr ));
$ ("Span: eq (2)"). text (jQuery. inArray ("David", arr ));

JQuery. unique (array) (deduplication)

JQuery. unique (divs)


3. Test operations

JQuery. isFunction (obj) (whether it is a function)
Function stub (){
}
Var objs = [
Function (){},
{X: 15, y: 20 },
Null,
Stub,
"Function"
];

JQuery. each (objs, function (I ){
Var isFunc = jQuery. isFunction (objs [I]);
$ ("Span: eq (" + I + ")"). text (isFunc );
});


4. String operations

JQuery. trim (str) (remove spaces)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.