Html遍歷物件、list集合、陣列
DreamWeaver_Zhou發表於2018-02-08
- 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 > 使用者名稱 < /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 = "";
-
-
- 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>/