html
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> </head> <body> <input type="text" onkeydown="abc(event)"> <script> function abc(e) { var keyNum = e.keyCode; // String.fromCharCode var keyChar = String.fromCharCode(keyNum); console.log(keyNum + keyChar); } </script> </body> </html>
vue
<input class="ipt" type="text" @keydown="test6"> test6(e) { // console.log(event.keyCode + '----' + event.target.value); console.log(e.keyCode); var ipt = document.querySelector('.ipt'); // console.log(ipt); if (e.keyCode == 13) { localStorage.setItem('name', ipt.value); ipt.value = ''; } }