当前位置: 首页 > 图文教程 > 网络编程 > Javascript > Javascript 二维数组

Javascript
form中限制文本字节数js代码
use jscript with List Proxy Server Information
use jscript List Installed Software
List Installed Software Features
List Information About the Binary Files Used by an Application
List the Codec Files on a Computer
List the UTC Time on a Computer
List Installed Hot Fixes
excel操作之Add Data to a Spreadsheet Cell
Add Formatted Data to a Spreadsheet
Apply an AutoFormat to an Excel Spreadsheet
JavaScript语法着色引擎(demo及打包文件下载)
类之Prototype.js学习
一款JavaScript压缩工具:X2JSCompactor
iis6+javascript Add an Extension File
jscript之Open an Excel Spreadsheet
jscript之Read an Excel Spreadsheet
jscript之List Excel Color Values
去除图像或链接黑眼圈的两种方法总结
Add a Formatted Table to a Word Document

Javascript 二维数组


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2010-01-10   浏览: 365 ::
收藏到网摘: n/a

Javascript二维数组的实现代码,需要的朋友可以参考下。
复制代码 代码如下:

<script language="JavaScript">
var x=3, y=4;
var data = new Array(x);
for (var i=0; i<x; i++)
{
data[i] = new Array(y);
}
for (var i=0; i<x; i++)
{
for (var j=0; j<y; j++)
{
data[i][j] = i + j;
}
}
// var myarr = new Arrqy(3,4)
// 定义的是一个有两个元素的一维数组,3和4是各个元素的值
// 根据二维数组动态生成表格
function buildTable(tableId, data)
{
for (var i=0; i<data.length; i++)
{
var row = document.getElementById(tableId).insertRow();
for (var j=0; j<data[i].length; j++)
{
var cell=row.insertCell(j);
cell.innerText=data[i][j];
}
}
}
</script>
//实现举例
<table id="table1"></table>
<input type="button" value="生成表格" onclick="buildTable('table1',data)">