1.擴展:
[javascript]
$(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);
});
[javascript]
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代碼:
[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代碼:
[javascript]
$(document).ready(function(){
$("p").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.
[javascript]
// var json=[{"name":"aa","age":18},{"name":"ab","age":19}];
// alert($(json)[0].age);
摘自 洋洋的專欄