Ajax遍历jSon后对每一条数据进行相应的修改和删除(代码分享)
废话不多说了,直接给大家贴代码了,具体代码如下所示:
$.ajax({ url: "/business/findpersons.json", dataType: "json", type:"GET", success: function(doc) { var objs=eval(doc); for (var i = 0; i < objs.length; i++){ var personid=objs[i].personId; var name=objs[i].personName; var email=objs[i].personEmail; var sector=objs[i].personSector; var position=objs[i].personPosition; var password=objs[i].personPassword; $("#personList thead").append( "<tr>"+ "<th>"+name+"</th>"+ "<th>"+password+"</th>"+ "<th>"+email+"</th>"+ "<th>"+position+"</th>"+ "<th><input type='button' value='删除' name="+i+" class='deletePersonBut'></th>"+ "<th><input type='button' value='修改' name="+i+" class='updataPersonBut'></th>"+ "</tr>" ); var getA = "#personList .deletePersonBut[name="+ i + "]";//就这里获取的原因,那个i=objs.length的原因,感觉应该就是闭包的问题。 $(getA).click(function(){ var thid=$(this).parent(); var pid=thid.children(".deletePersonBut").attr('name'); alert(objs[pid].personId); }); var getA = "#personList .updataPersonBut[name="+ i + "]";//就这里获取的原因,那个i=objs.length的原因,感觉应该就是闭包的问题。 $(getA).click(function(){ var thid=$(this).parent(); var pid=thid.children(".updataPersonBut").attr('name'); alert(objs[pid].personId); }); } } });
相关推荐
zrtlin 2020-11-09
xuebingnan 2020-11-05
wikiwater 2020-10-27
heheeheh 2020-10-19
Crazyshark 2020-09-15
softwear 2020-08-21
ZGCdemo 2020-08-16
jczwilliam 2020-08-16
littleFatty 2020-08-16
idning 2020-08-03
jinxiutong 2020-07-26
lanzhusiyu 2020-07-19
Skyline 2020-07-04
xiaofanguan 2020-06-25
Aveiox 2020-06-23
dragonzht 2020-06-17