asp下使用數組存放資料的代碼_應用技巧

來源:互聯網
上載者:User
asp用用戶端數組存放資料,這種應用我已經見過很多。但最近在研究幾套流量交換聯盟系統時,這種技術才引起了我的注意。

下面我講講如何運用,先給出個沒有結合ASP,就單純適用javascript的例子。
1.js
複製代碼 代碼如下:

var a = new Array(); 
var temp = "<table>"; 
a[0] = new Array(1,"阿會楠","男");  
a[1] = new Array(2,"小白兔","女"); 
a[2] = new Array(3,"小琦","女"); 
for(var i = 0;i < a.length;i ++) 

        temp = temp + "<tr>" 
        for(var j = 0;j < a[0].length;j ++) 
        { 
                 temp = temp + "<td>" + a[i][j] + "</td>"; 
        } 
        temp = temp + "</tr>" 

temp = temp + "</table>"; 
document.write(temp); 

1.html
複製代碼 代碼如下:

<html> 
 <head> 
  <meta http-equiv="Content-Type" content="text/html; charset=GB2312" /> 
  <title>用數組存放資料</title> 
 </head> 
 <body> 
            <script language="JavaScript" type="text/javascript" src="1.js"></script> 
 </body> 
</html> 

1.html的輸出結果:
1 阿會楠 男 
2 小白兔 女 
3 小琦 女 
 看到輸出結果,你也許就想到我們該從那個js檔案入手了,是的,我們把1.html中的 <script language="JavaScript" type="text/javascript" src="1.js"></script>
換成 <script language="JavaScript" type="text/javascript" src="1.asp"></script>
把1.js另存新檔1.asp並做如下修改:
複製代碼 代碼如下:

var a = new Array(); 
var temp = "<table>"; 
<% 
資料庫連接代碼,開啟串連 
For i = 1 To 3 
      If objRs.eof Then Exit For 
%> 
a[<%=i%>] = new Array(<%=objRs(0)%>,"<%=objRs(1)%>","<%=objRs(2)%>") 
<%  
objRs.movenext 
Next 
%> 
for(var i = 0;i < a.length;i ++) 

     temp = temp + "<tr>" 
     for(var j = 0;j < a[0].length;j ++) 
     { 
           temp = temp + "<td>" + a[i][j] + "</td>"; 
     } 
    temp = temp + "</tr>" 

temp = temp + "</table>"; 
document.write(temp); 

asp代碼部分我並沒有貼出完整的代碼,只稍微寫了一點,請自己補充。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.