在Jquery中遍历集合,怎样用each实现
$.ajax({type:"POST",contentType:"application/json",url:"WebService.asmx/GetAllStu",da...
$.ajax({
type: "POST",
contentType: "application/json",
url: "WebService.asmx/GetAllStu",
data: "{}",
dataType: "json",
success: function(result) {
for (var i = 0; i < result.d.length; i++) {
var $tr = "<tr><td>" + result.d[i]["StuID"] + "</td><td>" + result.d[i]["StuName"] + "</td><td>" + result.d[i]["StuSex"] + "</td></tr>";
$("tr:last").after($tr);
}
}
}); 展开
type: "POST",
contentType: "application/json",
url: "WebService.asmx/GetAllStu",
data: "{}",
dataType: "json",
success: function(result) {
for (var i = 0; i < result.d.length; i++) {
var $tr = "<tr><td>" + result.d[i]["StuID"] + "</td><td>" + result.d[i]["StuName"] + "</td><td>" + result.d[i]["StuSex"] + "</td></tr>";
$("tr:last").after($tr);
}
}
}); 展开
3个回答
展开全部
这个 一看就懂啦
<script>
var t = [{a:"1",b:"2"},{a:"3",b:"4"},{a:"5",b:"6"}];
$(t).each(function(){
alert("a="+this.a+" b="+this.b)
});
</script>
<script>
var t = [{a:"1",b:"2"},{a:"3",b:"4"},{a:"5",b:"6"}];
$(t).each(function(){
alert("a="+this.a+" b="+this.b)
});
</script>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
//如果result是JSON类型数据 如{aa:"bb"}, i为name即 aa , j为value即 bb
$.each(result, function(i, j) {
alert("i:" + i + ",j" + j);
});
$.each(result, function(i, j) {
alert("i:" + i + ",j" + j);
});
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
楼上正解
$.each(result.d,function(key,value){
var $tr = "<tr><td>" + value.StuId+ "</td><td>" + value.StuName + "</td><td>" + value.StuSex + "</td></tr>";
$("tr:last").after($tr);
});
$.each(result.d,function(key,value){
var $tr = "<tr><td>" + value.StuId+ "</td><td>" + value.StuName + "</td><td>" + value.StuSex + "</td></tr>";
$("tr:last").after($tr);
});
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询