How to Use extended method extend in Jquery: jqueryextend
During Jquery development, extend is a common parameter processing function, especially for the use of default values.
The Extension Method prototype of Jquery is:
var v=$.extend(dest,src1,src2,[,src3...]);
The function is to merge src1, src2, and src3 into the dest and return the merged dest.
However, the default value cannot be changed during use,
As follows:
Var defaut = {'selector ': 'select', 'default': 'default', 'backcolor':' # 85e0000', 'forecolor': '#000 '}; var src = {'selector ': 'ss', 'default': 'joke', 'backcolor': '# fff', 'forecolor': 'red '};
If we use
var v=$.extend(dfault,src);
For parameter processing, the default value for the next processing is the value after the processing, rather than the actual default value.
We can use the following code:
var v=$.extend({},dfault,src);
That is, we use an empty object as the target parameter (default) and use the default parameter as the first source parameter (src). In this way, the merged parameter is returned, however, our default has not been changed and can be used again!
In this way, the default value remains unchanged!
You can use extend ({example and explain it to JQUERY ).
The extend extension method is prototype extend (dest, src1, src2, src3 ...);
It means to merge src1, src2, src3... into the dest, and the returned value is the merged dest. It can be seen that the structure of the dest is modified after the method is merged. If you want to obtain the merged result but do not want to modify the dest structure.
Var newSrc = $. extend ({}, src1, src2, src3 ...)
In this way, you can merge src1, src2, src3... and return the merged result to newSrc.
That is to say, if the following parameter has the same name as the preceding parameter, the following parameter will overwrite the preceding parameter value.
Var result = $. extend ({}, {name: "Tom", age: 21 },{ name: "Jerry", sex: "Boy "})
Then the merged result
Result = {name: "Jerry", age: 21, sex: "Boy "}
The dest parameter in the extend method prototype can be omitted. If this parameter is omitted, the method can only have one src parameter and merge the src parameter into the object that calls the extend method.
$. Extend ({hello: function () {alert ('hello') ;}}); merge the hello method into the global object of jquery.
How can I use the selector to select the class name $ ("className") for the jqueryfnextend extension method?
Try $ (". className"). eq (0). comeOn ();