日期:2014-05-16 浏览次数:20545 次
$.getScript("/js/user.js");
[ var data = { "name": "a", "sex": "男", "email": "a@163.com" }, { "name": "b", "sex": "女", "email": "b@163.com" } var strHTML = ""; $.each(data, function(index,entry) { //遍历获取的数据 strHTML += "<p>编号:" + index + "<br>"; strHTML += "姓名:" + entry["name"] + "<br>"; strHTML += "性别:" + entry["sex"] + "<br>"; strHTML += "邮箱:" + entry["email"] + "</p><hr>"; }) $("#mydata").html(strHTML); ]
$("#ajaxLoadJson").click(function(){ $.getJSON("js/user.json", function(data) { $("#divTip").empty(); //先清空标记中的内容 var strHTML = ""; //初始化保存内容变量 $.each(data, function(InfoIndex, Info) { //遍历获取的数据 strHTML += "姓名:" + Info["name"] + "<br>"; strHTML += "性别:" + Info["sex"] + "<br>"; }) $("#divTip").html(strHTML); //显示处理后的数据 }) });
[ { "name": "a", "sex": "男", "email": "a@163.com" }, { "name": "b", "sex": "女", "email": "b@163.com" } ]
$("#ajaxLoadhtml").click(function() { //按钮点击事件 $("#ajax").load("index.jsp h3"); //load()方法加载数据 })
<html> <head> </head> <body> <h2>Hello World!</h2> <h3>你好</h3> </body> </html>