-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask18.html
More file actions
61 lines (61 loc) · 1.7 KB
/
task18.html
File metadata and controls
61 lines (61 loc) · 1.7 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
52
53
54
55
56
57
58
59
60
61
<!DOCTYPE html>
<html>
<head>
<title>Task 18</title>
<meta charset="utf-8">
<style type="text/css">
.display {
display: inline-block;
height: 40px;
background-color: red;
text-align: center;
font-size: 30px;
color: #ffffff;
margin-right: 10px;
margin-top: 5px;
padding: 10px;
}
</style>
</head>
<body id="body">
<input type="text" id="inputData">
<button id="inLeft" onclick="inLeftFunc()">左侧入</button>
<button id="inRight" onclick="inRightFunc()">右侧入</button>
<button id="outLeft" onclick="outLeftFunc()">左侧出</button>
<button id="outRight" onclick="outRightFunc()">右侧出</button>
<div id="display"></div>
<script type="text/javascript">
var body = document.getElementById('body');
var inputData = document.getElementById('inputData');
var inLeft = document.getElementById('inLeft');
var inRight = document.getElementById('inRight');
var outLeft = document.getElementById('outLeft');
var outRight = document.getElementById('outRight');
var display = document.getElementById('display');
function inLeftFunc() {
if (inputData!="") {
var div = document.createElement('div');
div.setAttribute("class","display");
div.innerHTML = inputData.value;
display.insertBefore(div,display.firstChild);
inputData.value = "";
}
}
function inRightFunc() {
if (inputData!="") {
var div = document.createElement('div');
div.setAttribute("class","display");
div.innerHTML = inputData.value;
display.appendChild(div);
inputData.value = "";
}
}
function outLeftFunc() {
display.removeChild(display.firstChild);
}
function outRightFunc() {
display.removeChild(display.lastChild);
}
</script>
</body>
</html>