<header>
<h2 class="title">InputEvent -> inputType</h2>
<p class="description">Визначає тип змін, внесених до текстового поля.</p>
</header>
<main>
<div class="result">
<label for="textInput">Введіть текст або скористайтесь буфером обміну:</label><br>
<input type="text" id="textInput" placeholder="Введіть текст тут" />
<p id="output">Тип введення: <span id="inputType">невідомо</span></p>
</div>
</main>
body {
font-size: 16px;
line-height: 1.5;
font-family: monospace;
}
header {
background-color: #f1f1f1;
margin-bottom: 25px;
padding: 15px;
box-shadow: 0px 0px 3px 0px rgba(118, 118, 118, 1);
box-shadow: 0px 0px 3px 0px rgba(118, 118, 118, 1);
box-shadow: 0px 0px 3px 0px rgba(118, 118, 118, 1);
}
header h2.title {
padding-bottom: 15px;
border-bottom: 1px solid #999;
}
header p.description {
font-style: italic;
color: #222;
}
.result {
background-color: #f8f8f8;
padding: 15px;
box-shadow: 0px 0px 3px 0px rgba(118, 118, 118, 1);
box-shadow: 0px 0px 3px 0px rgba(118, 118, 118, 1);
box-shadow: 0px 0px 3px 0px rgba(118, 118, 118, 1);
}
label {
font-weight: bold;
}
#textInput {
margin-top: 10px;
width: 100%;
padding: 8px;
font-size: 1em;
}
#output {
margin-top: 15px;
font-size: 1.1em;
}
const textInput = document.getElementById('textInput');
const inputTypeOutput = document.getElementById('inputType');
textInput.addEventListener('input', (event) => {
inputTypeOutput.textContent = event.inputType;
switch(event.inputType) {
case 'insertText':
inputTypeOutput.style.color = 'green';
break;
case 'deleteContentBackward':
inputTypeOutput.style.color = 'red';
break;
case 'insertFromPaste':
inputTypeOutput.style.color = 'blue';
break;
default:
inputTypeOutput.style.color = 'black';
}
});
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.