-
Notifications
You must be signed in to change notification settings - Fork 3
/
test.html
76 lines (67 loc) · 1.66 KB
/
test.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Code Input</title>
<style>
.input-container {
display: flex;
flex-wrap: wrap;
border: 1px solid #ccc;
padding: 5px;
width: 300px;
}
.input-container input {
border: none;
outline: none;
flex-grow: 1;
padding: 5px;
}
.tag {
display: inline-flex;
align-items: center;
background-color: #e0e0e0;
border-radius: 3px;
padding: 5px;
margin: 3px;
}
.tag .remove-tag {
cursor: pointer;
margin-left: 5px;
}
</style>
</head>
<body>
<div class="input-container" id="inputContainer">
<input type="text" id="codeInput" placeholder="Enter codes..." />
</div>
<script>
const inputContainer = document.getElementById('inputContainer');
const codeInput = document.getElementById('codeInput');
// Function to create and add a new tag
function addTag(code) {
const tag = document.createElement('span');
tag.classList.add('tag');
tag.textContent = code;
const removeTag = document.createElement('span');
removeTag.classList.add('remove-tag');
removeTag.textContent = 'x';
removeTag.onclick = () => tag.remove();
tag.appendChild(removeTag);
inputContainer.insertBefore(tag, codeInput);
}
// Handle input
codeInput.addEventListener('keypress', function (e) {
if (e.key === 'Enter' || e.key === ',') { // Enter or comma separates codes
e.preventDefault();
const code = codeInput.value.trim();
if (code) {
addTag(code);
codeInput.value = ''; // Clear input
}
}
});
</script>
</body>
</html>