-
转载自: 网络
-
-
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 = "";
-
-
-
var obj =[{"name":"项海军","password":"123456"}];
-
$("#result").html("------------遍历对象 .each的使用-------------");
-
alert(obj);
-
-
$.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>username</th>
-
<th>password</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 = "";
-
-
-
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>
-
------------此部分同1中的body部分--------------------
-
-
</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 = "";
-
-
-
var obj =[{"name":"项海军","password":"123456"},{"name":"科比","password":"333333"}];
-
$("#result").html("遍历List集合 .each的使用");
-
alert(obj);
-
-
$.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>
-
------------此部分同1中的body部分--------------------
-
-
</BODY>
-
</HTML>