回到首页
个人中心
反馈问题
注册登录
下载APP
代码
提交代码
<input type="text" class="input-here"> <div class="log"></div> <script> var inputEle = document.querySelector('.input-here'); var logEle = document.querySelector('.log'); inputEle.onkeydown = function(event) { var ele = document.createElement('p'); ele.innerText = '按下了' + event.keyCode; logEle.appendChild(ele); } inputEle.addEventListener('keyup', function(event) { var ele = document.createElement('p'); ele.innerText = '弹起了' + event.keyCode; logEle.appendChild(ele); }); </script>
运行结果