-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask20.html
More file actions
70 lines (70 loc) · 2.06 KB
/
task20.html
File metadata and controls
70 lines (70 loc) · 2.06 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
62
63
64
65
66
67
68
69
70
<!DOCTYPE html>
<html>
<head>
<title>Task 20</title>
<meta charset="utf-8">
<style type="text/css">
.textArea {
width: 150px;
height: 100px;
outline: none;
}
.display {
display: inline-block;
text-align: center;
line-height: 20px;
height: 30px;
padding: 10px 10px 0 10px;
margin: 10px;
background-color: pink;
}
.select {
display: inline-block;
text-align: center;
line-height: 20px;
height: 30px;
padding: 10px 10px 0 10px;
margin: 10px;
background-color: red;
color: #ffffff;
}
</style>
</head>
<body>
<textarea class="textArea" id="textArea" placeholder="请输入内容..."></textarea>
<button id="insert" onclick="insertFunc()">插入</button>
<button id="find" onclick="findFunc()">查询</button>
<input type="text" id="textFind" placeholder="请输入要查询内容...">
<div id="print"></div>
<script type="text/javascript">
var text = document.getElementById('textArea');
var insert = document.getElementById('insert');
var find = document.getElementById('find');
var textFind = document.getElementById('textFind');
var print = document.getElementById('print');
function insertFunc() {
var textCon = text.value.split(/[ ,,\n]/g);
for(var i = 0 ; i < textCon.length ; i++) {
var idvalue = textCon[i].toString();
var div = document.createElement('div');
div.setAttribute("class","display");
div.setAttribute("id",idvalue);
div.innerHTML = textCon[i];
print.appendChild(div);
}
}
function findFunc() {
var div = document.getElementsByTagName('div');
for(var i = 1 ; i < div.length ; i++) {
if(div[i].innerHTML === textFind.value) {
var idValue = textFind.value.toString();
var disDiv = document.getElementById(idValue);
// disDiv.style.color = "red";
disDiv.setAttribute("class","select");
}
}
textFind.value = "";
}
</script>
</body>
</html>