我有以下代码,适用于除 Enter、Shift 等之外的所有键。
$(document).ready(function(){
$('input[name="tmp_post_tag"]').keypress(function(evt){
alert("hello");
});
});
为什么回车后不起作用?这就是我想要它做的。 我尝试过 evt.char、evt.keyCode evt.which 但没有任何效果。
最佳答案
您需要使用 KeyDown()
事件,它将在所有特殊键上触发,包括 enter、alt、shift 等等...
检查此代码:
$(document).ready(function(){
$('input[name="tmp_post_tag"]').keydown(function(evt){
console.log('Key pressed : ' + evt.keyCode)
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="input" name="tmp_post_tag" placeholder="press key here" />
关于javascript - 如何定位回车键事件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52702071/