以下程序是動態添加刪除table行的javascript,IE6 上測試通過:
?1
<!
DOCTYPE?HTML?PUBLIC?
"
-//W3C//DTD?HTML?4.0?Transitional//EN
"
>
?2
<
HTML
>
?3
<
HEAD
>
?4
<
TITLE
>
?動態添加元素?
</
TITLE
>
?5
<
META?NAME
=
"
Generator
"
?CONTENT
=
"
EditPlus
"
>
?6
<
META?NAME
=
"
Author
"
?CONTENT
=
""
>
?7
<
META?NAME
=
"
Keywords
"
?CONTENT
=
""
>
?8
<
META?NAME
=
"
Description
"
?CONTENT
=
""
>
?9
</
HEAD
>
10
<
SCRIPT?LANGUAGE
=
"
JavaScript
"
>
11
<!--
12
var
?n?
=
?
1
;
13
function
?testAdd()
14
{
15
????
var
?tr?
=
?document.getElementById(
"
xxxx
"
).insertRow(
1
);
16
????tr.id
=
"
new_
"
+
n;
17
????
var
?c1?
=
?tr.insertCell();
18
????c1.innerText
=
"
xxx
"
+
n;
19
????
var
?c2?
=
?tr.insertCell();
20
????c2.innerText
=
"
bbb
"
;
21
22
????
var
?c3?
=
?tr.insertCell();
23
????c3.innerHTML
=
"
<a?href='#'?onclick=doDelete('new_
"
+
n
+
"
')>del</a>
"
;
24
????n
++
;????
25
}
26
function
?doDelete(i)
27
{
28
??
var
?tr?
=
?document.getElementById(i);
29
30
??document.getElementById(
"
xxxx
"
).deleteRow(tr.rowIndex);
31
}
32
//
-->
33
</
SCRIPT
>
34
<
BODY
>
35
<
input?type
=
"
button
"
?value
=
"
+
"
?onclick
=
"
testAdd()
"
>
36
<
table?name
=
"
tt
"
?border
=
"
1
"
?id
=
"
xxxx
"
>
37
<
tr?id
=
"
xxx
"
>
38
??
<
td
>
name22222
</
td
>
39
??
<
td
>
value
</
td
>
40
??
<
td
>&
nbsp;
</
td
>
41
</
tr
>
42
</
table
>
43
</
BODY
>
44
</
HTML
>
45

?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

36

37

38

39

40

41

42

43

44

45
