84669 人學習
152542 人學習
20005 人學習
5487 人學習
7821 人學習
359900 人學習
3350 人學習
180660 人學習
48569 人學習
18603 人學習
40936 人學習
1549 人學習
1183 人學習
32909 人學習
谁用过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