<input type="text" onfocus="javascript:onFocus(this);">
<script language="javascript">
function onFocus(entity)...{
var isie = (document.all) ? true : false;
entity.onkeypress = onKeypress;
if (!isie)...{
document.captureEvents(Event.KEYPRESS);
}
}
function onKeypress(e)...{
var isie = (document.all) ? true : false;
var key;
if (isie)
key = window.event.keyCode;
else
key = e.which;
alert(key);
}
</script>
本文介绍了一种使用JavaScript实现的键盘事件监听方法,通过onfocus和onkeypress事件,可以捕获用户在输入框中按键的行为,并展示按键的键码。
1039

被折叠的 条评论
为什么被折叠?



