键盘按键js效果
<input id="name" type="text" >
JS:
<script> document.onkeydown = function(){ var name = document.getElementById('name'); //Enter键,console输出 if(event.keyCode ==13) { console.log(name.value); } //ESC键,清空 if(event.keyCode == 27) { name.value = '' ; } }; </script>