1.擴充:
$(document).ready(function(){var aa={"uname":"dd","uage":19,"show":function(){alert(1);}};var bb=$.extend({},aa,{"usex":"男","uname":"bb"});//相當於繼承父類aa//var bb=$.extend({},{"usex":"男","uname":"bb"},aa);//aa放後面則把前面的覆蓋了alert(aa.uname+" "+bb.uage+" "+bb.uname);});
var settings = { validate: false, limit: 5, name: "foo" };var options = { validate: true, name: "bar" };jQuery.extend(settings, options);
結果:
settings == { validate: true, limit: 5, name: "bar" } 2.Ajax:java代碼:
response.setContentType("text/html");PrintWriter out = response.getWriter();String name=request.getParameter("uname");String location=request.getParameter("location");System.out.println(name+" "+location);//String str="{\"users\":[{\"uname\":\"zs\",\"age\":1},{\"uname\":\"bb\",\"age\":5}]}";String str="{'users':[{'uname':'zs','age':1},{'uname':'bb','age':5}]}";str=str.replaceAll("'", "\"");out.print(str);
jquery代碼:
$(document).ready(function(){$("div").bind("click",{"age":20},function(){$.ajax({url: "/MyJs/MyTestServlet",type:"GET",data: "uname=John&location=Boston",dataType:"json",success:function(msg){alert(msg.users[0].uname);}});});});
3.
// var json=[{"name":"aa","age":18},{"name":"ab","age":19}];// alert($(json)[0].age);