Create ex8 Input Number checker
This commit is contained in:
@@ -0,0 +1,28 @@
|
|||||||
|
<!doctype html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>JS Tester</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="output"></div>
|
||||||
|
<input type="text" name="myNum1">
|
||||||
|
<input type="text" name="myNum2">
|
||||||
|
<script>
|
||||||
|
const eles = document.querySelectorAll("input");
|
||||||
|
const output = document.querySelector(".output");
|
||||||
|
eles.forEach(el => {
|
||||||
|
el.addEventListener("keydown", (e) => {
|
||||||
|
if (!isNaN(e.key)) {
|
||||||
|
output.textContent += e.key;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
el.addEventListener("keydown", (e) => {
|
||||||
|
console.log(e.key);
|
||||||
|
})
|
||||||
|
el.addEventListener("paste", (e) => {
|
||||||
|
console.log('pasted');
|
||||||
|
})
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
Reference in New Issue
Block a user