http://www.cnblogs.com/scy251147/archive/2010/11/30/1892411.html
主要用到了JQuery中的append和appendto的方法,具体代码如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
<
html
>
<
head
>
<
meta
http-equiv
=
"Content-Type"
content
=
"text/html; charset=gb2312"
>
<
title
>动态创建表格</
title
>
<
script
type
=
"text/javascript"
src
=
"Scripts/jquery-1.3.2.js"
></
script
>
<
script
type
=
"text/javascript"
>
function CreateTable(rowCount,cellCount)
{
var table=$("<
table
border=\"1\">");
table.appendTo($("#createtable"));
for(var i=0;i<
rowCount
;i++)
{
var tr=$("<tr></
tr
>");
tr.appendTo(table);
for(var j=0;j<
cellCount
;j++)
{
var td=$("<td>"+i*j+"</
td
>");
td.appendTo(tr);
}
}
trend.appendTo(table);
$("#createtable").append("</
table
>");
}
</
script
>
</
head
>
<
body
>
<
input
type
=
"button"
value
=
"添加表格"
onClick
=
"CreateTable(5,6)"
>
<
input
type
=
"button"
value
=
"添加行"
>
<
div
id
=
"createtable"
></
div
>
<
div
id
=
"createrow"
></
div
>
</
body
>
</
html
>
|