JQuery1.6 usage method 3 _ jquery

Source: Internet
Author: User
JQuery1.6 method 3. If you want to learn jquery, refer. A = {id: 1, get: function () {alert (this. id )}}
$ ("# Test"). click (a. get) // at this time, the id is not 1, but test
If you want to get 1, you must change the context $.
$. Proxy () is used to change the current context.
$ ("# Test"). click ($. proxy (a, "get "))
$ ("# Test"). click ($. proxy (a. get, ))
Proxy: function (fn, context) {// change the context of the function. this indicates the set object.
The parameters here can be either of the following methods: the method of the function fn context
Function Method fn [context] function fn
If (typeof context = "string") {// if content is a string, it is considered to be a fn method fn [context]. Then, determine whether it is a function.
Var tmp = fn [context];
Context = fn;
Fn = tmp;
}
If (! JQuery. isFunction (fn) {// no function returns undefined immediately
Return undefined;
}
Var args = slice. call (arguments, 2), // use the parameters following fn and content as the function parameters to be executed
Proxy = function (){
Return fn. apply (context, args. concat (slice. call (arguments); // return the executable function with the specified context set. fn indicates the number of executable rows and this indicates content, args. concat (slice. call (arguments) as a parameter,
};
Proxy. guid = fn. guid = fn. guid | proxy. guid | jQuery. guid ++; // a global counter that can be used to identify and delete a function
Return proxy;
},
// The access method is mainly used inside jquery for attr, prop, and css. It mainly sets the values of one or more attributes and styles of DOM groups (jquery objects, gets the value of an attribute and style in a DOM group (jquery object ).
// Elems operation object group, key attribute, value Attribute value, exec default true, fn is used to operate the function, pass mainly sets val, css, html, text, data, width, height, and offset should be true.
Access: function (elems, key, value, exec, fn, pass ){
Var length = elems. length;
// Set multiple attributes
If (typeof key = "object") {// if the attribute value is an object, set the attributes and corresponding values of the dom group (jquery object) cyclically.
For (var k in key ){
JQuery. access (elems, k, key [k], exec, fn, value );
}
Return elems; // return results
}
// Set a single attribute
If (value! = Undefined) {// if the value exists, you can set an attribute to a group of objects or a single object. If the value does not exist, you can obtain an attribute value of doms [0] (jquery object, only one object can be returned, or undefiend is returned because the object does not exist;
Exec =! Pass & exec & jQuery. isFunction (value); // currently, the default pass of jquery is null, exec is true, and value is a function.
For (var I = 0; I <length; I ++ ){
Fn (elems [I], key, exec? Value. call (elems [I], I, fn (elems [I], key): value, pass); // If exec is true ,, input the sequence of the operation object and the operation property value as the parameter. Otherwise, set the attribute key value to value.
}
Return elems;
}
// Get attributes
Return length? Fn (elems [0], key): undefined;
},
Now: function () {// returns the current time
Return (new Date (). getTime ();
},

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.