-
jQuery遍历对象/数组/集合
-
转载自: 网络
-
-
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>
-
相关阅读:
【python-leetcode107-树的宽度遍历】二叉树的层次遍历Ⅱ
Spring依赖
Dubbo依赖
免费内网穿透
Oracle分析函数Over()
测压工具
编译器版本
修改gridfilters.js源码,往后台多传递一个参数,并设置NumericFilter、StringFilter默认提示信息
网站10分钟不操作会话退出
win10彻底关闭windows defender,解决无故占用大量CPU问题
-
原文地址:https://www.cnblogs.com/wgwyanfs/p/7102582.html
Copyright © 2020-2023
润新知