-
Notifications
You must be signed in to change notification settings - Fork 0
/
TestDOM02.html
114 lines (98 loc) · 3.1 KB
/
TestDOM02.html
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style type="text/css">
*{
margin: 0px;
padding: 0px;
}
body{
text-align: center;
}
#div01{
width: 1920px;
height: 300px;
}
input{
width: 250px;
}
label{
display: inline-block;
min-width: 50px;/*或者 width: 100px;*/
}
input[type=button]{
width: 80px;
height: 40px;
background-color: #2d78f4;
}
#ta{
margin: auto;
}
#ta tr{
height: 40px;
text-align: center;
}
td{
border: 1px solid black;
}
#div03{
margin: 100px;
}
</style>
</head>
<body>
<div id="div01">
<div id="div03">
<form action="#" method="get">
<label for="iD">ID</label>
<input type="text" name="iD" id="iD" value="">
<label for="uname">Name</label>
<input type="text" name="uname" id="uname" value=""><br>
<label for="salary">Salary</label>
<input type="text" name="salary" id="salary" value="">
<label for="job">Job</label>
<input type="text" name="job" id="job" value=""><br>
<input type="button" name="" id="" value="Add" onclick="update()">
</form>
</div>
</div>
<hr>
<div id="div02">
<table border="1px" id="ta">
<tr style="text-align: center">
<td width="80px" >ID</td>
<td width="200px" >Name</td>
<td width="200px" >Salary</td>
<td width="200px" >Job</td>
<td width="200px" >Delete</td>
</tr>
</table>
</div>
<script >
function update() {
let ta=document.getElementById('ta');
let tr = ta.insertRow(1);
let cell0=tr.insertCell(0);
cell0.innerHTML=document.getElementById('iD').value;
let cell1=tr.insertCell(1);
cell1.innerHTML=document.getElementById('uname').value;
let cell2=tr.insertCell(2);
cell2.innerHTML=document.getElementById('salary').value;
let cell3=tr.insertCell(3);
cell3.innerHTML=document.getElementById('job').value;
let cell4=tr.insertCell(4);
cell4.innerHTML="<input type='button' value='删除' onclick='delRow(this)'/>";
}
function delRow(btn){
//获取table对象
var ta=document.getElementById("ta");
//获取要删除的行对象
var tr=btn.parentNode.parentNode;
//删除行
ta.deleteRow(tr.rowIndex);
}
</script>
</body>
</html>