一直在找一个爽的WEB网格控件,但总是让我很失望,最终还是重拾JS自己写。
这代码需要你先在页面做一个Table,然后就可以用这个代码在页面给你添加行了。
1
function $(id)
2
{
3
return document.getElementById(id);
4
}
5
6
var count =1;
7
8
var Grid =
{
9
10
Id:"table", //网格的客户端ID,
11
12
CellCount:0, //单元格数
13
14
CreateCell:function(tr,content) //创建单元格
15
{
16
17
var cell = tr.insertCell();
18
cell.name=name;
19
cell.appendChild(content)
20
return cell;
21
},
22
23
CreateCellContent:function(type,value,name) //创建单元格内容
24
{
25
var content = document.createElement(type);
26
switch(type)
{
27
case "a":
28
content.href="javascript:void";
29
content.onclick=value;
30
content.appendData(name);
31
break;
32
case "input":
33
content.value=value;
34
content.name=name;
35
default:
36
break;
37
}
38
39
return content;
40
},
41
42
CreateRow:function()
{ // 创建一行
43
44
return $(Grid.Id).insertRow();
45
46
47
}
48
49
}
50
51
function addrow() //调用示例
52
{
53
Grid.Id="t";
54
Grid.CellCount=2;
55
var row = Grid.CreateRow();
56
for(var i =1;i<=Grid.CellCount;i++)
57
{
58
var content = Grid.CreateCellContent("input","","in"+count.toString()+i);
59
var cell = Grid.CreateCell(row,content);
60
}
61
62
63
}
posted on 2007-11-09 12:17
bidaas 阅读(309)
评论(1) 编辑 收藏