关闭。这个问题需要debugging details .它目前不接受答案。
编辑问题以包含 desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem .这将帮助其他人回答问题。
7年前关闭。
Improve this question
<input class="inputVal">
<script type="text/javascript">
var myVal = document.getElementsByClassName('inputVal')[0];
myVal.addEventListener('keyup', function(e){
var count = myVal.value;
console.log(count)
});
</script>
最佳答案
尝试将事件绑定(bind)到 document
或 window
.如果一个元素不可聚焦且未聚焦,则键盘事件不会发送到它,而是发送到文档根目录(<body>
)。
关于javascript - addEventListener keyup Keydown 与 Keycode 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27245452/