Home > Web Front-end > JS Tutorial > body text

Share the detailed usage of jQuery.extend function

巴扎黑
Release: 2017-07-09 11:55:15
Original
973 people have browsed it

Recently studying jQuery. Record the usage of jQuery.extend extensionfunction.

1. Extend jQuerystatic method.


1Share the detailed usage of jQuery.extend function##$.extend(Share the detailed usage of jQuery.extend function {
2
test:Share the detailed usage of jQuery.extend functionShare the detailed usage of jQuery.extend functionfunction(){alert('test function')}
3
})Usage: $.test()


2. Merge multiple

objects .## is jQuery.extend(css1, css2) as an example. css1 and css2 have some attributes
(The method will still deal with it, here we talk about attributes).
The extend function will add the attributes that css2 has but does not have in css2 to css1. If a certain attribute of css2 shares the name of a certain attribute of css1, then The properties of css2 will be used to overwrite the properties of the same name of css1. css1 is the final integration object. Or you can also use: var newcss = jquery.extend(css1,css2) newcss is the merged new object. var newcss = jquery.extend({},css1,css2) newcss is the merged new object. And it does not destroy the structure of css1.

1 //Usage: jQuery.extend(obj1,obj2,obj3,..)
2Share the detailed usage of jQuery.extend functionShare the detailed usage of jQuery.extend functionvar Css1={size: "10px",style: "oblique" }
3Share the detailed usage of jQuery.extend functionShare the detailed usage of jQuery.extend function##var Css2={size: "12px",style : "oblique",weight: "bolder"}
##4
##$.jQuery.extend(Css1,Css2) 5
//Result: The size attribute of Css1 is overwritten, and inherits the weight attribute of Css26
// Css1 = {size: "12px",style: "oblique",weight: " bolder"}7
##3. Deeply nested objects

The new
extend
() allows you to merge nested objects more deeply. The example below is a good proof.

1 // Previous .extend()
## 2 jQuery. extend(
3Share the detailed usage of jQuery.extend function Share the detailed usage of jQuery.extend function##{ name: “John”, location: ##{ city: “Boston” } }, 4
     Share the detailed usage of jQuery.extend functionShare the detailed usage of jQuery.extend function##{ last: “Resig”, location: { state: “MA ” } } ## 5
);
6
// Result: 7
    // => { name: “John”, last: “Resig”, location: { state: “MA” } } 8
// New and more in-depth .extend()  9   jQuery.extend( true,   
10Share the detailed usage of jQuery.extend functionShare the detailed usage of jQuery.extend function   { name: “John”, location: { city: “Boston” } },   
11Share the detailed usage of jQuery.extend functionShare the detailed usage of jQuery.extend function     { last: “Resig”, location: { state: “MA” } }   
12  );   
13  // 结果   
14   // => { name: “John”, last: “Resig”,   
15  //      location: { city: “Boston”, state: “MA” } }  
16
17

   

The above is the detailed content of Share the detailed usage of jQuery.extend function. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!