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