84669 person learning
152542 person learning
20005 person learning
5487 person learning
7821 person learning
359900 person learning
3350 person learning
180660 person learning
48569 person learning
18603 person learning
40936 person learning
1549 person learning
1183 person learning
32909 person learning
谁用过input事件?如何在inpu的事件对象中获取自己输入的字符?
回答的都不行,我需要判断当前按下的值,你们这样的我无法检测到backspace被按下
业精于勤,荒于嬉;行成于思,毁于随。
event.target.value
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> </head> <body> <input id='test' type='text'> <script> document.getElementById('test').addEventListener('input',function(e){ console.log(e.target.value); }) </script> </body> </html>
-----分割线----是回答得不行,还是你自己没有讲清楚?backspace的keycode是8
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> </head> <body> <input id='test' type='text'> <script> document.getElementById('test').addEventListener('keyup',function(e){ if(e.keyCode==8){ console.log('按了backspace键'); } }) </script> </body> </html>
html
<input type="text" id="test">
javascript
// jquery $('#test').on('keyup', function(event) { console.log(event.key) }) // 原生 var input = document.getElementById("test") input.addEventListener('keyup', function(event) { console.log(event.key) })
event.target.value
-----分割线----
是回答得不行,还是你自己没有讲清楚?
backspace的keycode是8
html
javascript