<html>
<head>
<title>Test</title>
<script type="text/javascript">
function showChar(e) {
if (e.keyCode != 16) {
alert(
"keyCode: " + e.keyCode + "\n"
+ "SHIFT key pressed: " + e.shiftKey + "\n"
);
}
}
</script>
</head>
<body onkeydown="showChar(event);">
<p>Press any character key, with or without holding down
the SHIFT key.<br /></p>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
如何在onkeydown事件处理程序方法中区分大写A和小写a?以上算法触发相同的keyCode值.我需要在按下onkeydown时检测大写字母.
注意:代码包含SHIFT键的例外.否则它不允许输入大写字母.顺便说一句,我需要使用onkeydown进行试验.