-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTableScript.js
More file actions
51 lines (47 loc) · 1.01 KB
/
TableScript.js
File metadata and controls
51 lines (47 loc) · 1.01 KB
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
var table;
var columb = 1;
var line = 0;
function creatTable(){
table = document.getElementById('myTable');
table.border = 1;
table.align = 'center';
var row = table.insertRow(0);
document.body.appendChild(table);
}
function addLine(){
var row = table.insertRow(0);
for(var i = 0; i < columb; i++){
var cell = row.insertCell(0);
cell.ondblclick = function(){
setText(this);
}
}
line++;
}
function addColumb(){
var trs = document.getElementsByTagName('tr');
for(var i = 0; i < line; i++){
var cell = trs[i].insertCell();
cell.ondblclick = function(){
setText(this);
}
}
columb++;
}
function setText(td){
var input = document.createElement('input');
input.value = td.innerHTML;
td.innerHTML = '';
input.type = 'text';
input.style.width = '60px';
input.style.height = '30px';
document.onkeyup = function (e) {
e = e || window.event;
if (e.keyCode === 13) {
var line = input.value;
td.removeChild(input);
td.innerHTML = line;
}
}
td.appendChild(input);
}