1.jquery遍历对象
< !DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" > <HTML > <HEAD > <TITLE > New Document < /TITLE>
<script language="javascript" type="text/javascript " src="jquery.min.js "></script>
<script type="text / javascript ">
$(function(){
var tbody = "";
//------------遍历对象 .each的使用-------------
//对象语法JSON数据格式(当服务器端回调回来的对象数据格式是json数据格式,必须保证JSON的格式要求,回调的对象必须使用eval函数进行转化(否则将得不到Object)。本文不作详细介绍服务器端回调的数据问题,我们将直接自定义对象)
var obj =[{"name ":"项海军","password ":"123456 "}];
$("#result ").html("------------遍历对象.each的使用-------------");
alert(obj);//是个object元素
//下面使用each进行遍历
$.each(obj,function(n,value) {
alert(n+' '+value);
var trs = "";
trs += " < tr > <td > " + value.name +" < /td> <td>" + value.password +"</td > </tr>";
tbody += trs;
});
$("#project").append(tbody);
});
</script > </HEAD>
<BODY>
<div id="result" style="font-size:16px;color:red;"></div >
<table cellpadding = 5 cellspacing = 1 width = 620 id = "project"border = "1" >
<tr >
<th > 用户名 < /th>
<th>密码</th >
</tr>
</table > </BODY>
</HTML >
2.jQuery遍历数组
< !DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" > <HTML > <HEAD > <TITLE > New Document < /TITLE>
<script language="javascript" type="text/javascript " src="jquery.min.js "></script>
<script type="text / javascript ">
$(function(){
var tbody = "";
//------------遍历数组 .each的使用-------------
var anArray = ['one','two','three'];
$("#result ").html("------------遍历数组.each的使用-------------");
$.each(anArray,function(n,value) {
alert(n+' '+value);
var trs = "";
trs += " < tr > <td > " +value+" < /td></tr > ";
tbody += trs;
});
$("#project ").append(tbody);
});
</script>
</HEAD>
<BODY>
<div id="result" style="font-size:16px;color:red;"></div > <table cellpadding = 5 cellspacing = 1 width = 620 id = "project"border = "1" > <tr > <th > 用户名 < /th>
<th>密码</th > </tr>
</table > </BODY>
</HTML >
3.jQuery 遍历List集合(其实与遍历一个对象没有太大区别,只是格式上的问题)
<!DOCTYPE HTML PUBLIC " - //W3C//DTD HTML 4.0 Transitional//EN">
< HTML > <HEAD > <TITLE > New Document < /TITLE>
<script language="javascript" type="text/javascript " src="jquery.min.js "></script>
<script type="text / javascript ">
$(function(){
var tbody = "";
//------------遍历List集合 .each的使用-------------
var obj =[{"name ":"项海军","password ":"123456 "},{"name ":"科比","password ":"333333 "}];
$("#result ").html("遍历List集合.each的使用");
alert(obj);//是个object元素
//下面使用each进行遍历
$.each(obj,function(n,value) {
alert(n+' '+value);
var trs = "";
trs += " < tr > <td > " +value.name+" < /td> <td>" + value.password +"</td > </tr>";
tbody += trs;
});
$("#project").append(tbody);
});
</script > </HEAD>
<BODY>
<div id="result" style="font-size:16px;color:red;">
</div >
<table cellpadding = 5 cellspacing = 1 width = 620 id = "project" border = "1" >
<tr >
<th > 用户名 < /th>
<th>密码</th >
</tr>
</table >
</BODY>
</HTML >
相关文章
- 02-20v-for遍历数组,对象与响应式方法
- 02-20关于dom数组对象遍历的坑
- 02-20vue_v-for_遍历数组_遍历对象
- 02-20vue v-for遍历数组和遍历对象的区别
- 02-20遍历每个数组对象,并且给每个对象添加一个相同的字段,值从另外一个数组取过来
- 02-20js遍历数组、对象、json
- 02-20jquery遍历对象,数组,集合
- 02-20Jquery 遍历数组
- 02-20Js处理后台json数组对象,遍历json数组对象,存入,排序
- 02-20HashMap集合存储学生对象并遍历