Jquery-api-$.extend ()-example:
1 <!DOCTYPE HTML>2 <HTML>3 <Head>4 <Scriptsrc= "Http://cdn.bootcss.com/jquery/1.11.2/jquery.min.js"></Script>5 </Head>6 <Body>7 8 <DivID= "Log"></Div>9 Ten <Script> One varObject1= { A Apple:0, - Banana: {weight: the, Price: -}, - Cherry: the the }; - varObject2= { - Banana: {Price: $}, - Durian: - + }; - + /*merge object2 into Object1*/ A $.extend (Object1, object2); at /*Json.stringify Not all browsers support, IE67 can not, this is a compatibility of the judgment - The typeof json!== "undefined" is used to determine whether the JSON class exists, is executed, and does not invoke the custom method. */ - varPrintobj= typeofJSON!= "undefined" ?json.stringify:function(obj) { - vararr= []; - $.each (obj,function(Key, Val) { - varNext=Key+ ": "; in Next+=$.isplainobject (val)?Printobj (val): Val; - /*test whether the object is a purely object (created with "{}" or "New Object")*/ to Arr.push (next); + }); - return "{ " +Arr.join (", ") + " }"; the }; * $ $("#log"). Append (Printobj (Object1));Panax Notoginseng </Script> - the </Body> + </HTML>
Jquery-api-$.extend ()-example