刚刚在写一个jQuery的案例,但keycode始终不能正常起作用,查阅了好多文档也不行,最终仔细对比后,结果让人哭笑不得!
e.keyCode中的 ”C“ 必须大写才行 !
之前已经犯过一次错了,没想到再次还会犯错
演示:
keycode 输出undefined 不能正常运行。
<!DOCTYPE html>
<html lang="en"><head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="jquery.min.js"></script>
</head><body>
<input type="text" id="title">
<script>
$(function() {
$("#title").on("keydown", function(e) {
log(e.keycode);
})
})
</script>
</body></html>
e.keyCode 就能正常输出啦!
<!DOCTYPE html>
<html lang="en"><head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="jquery.min.js"></script>
</head><body>
<input type="text" id="title">
<script>
$(function() {
$("#title").on("keydown", function(e) {
console.log(e.keyCode);
})
})
</script>
</body></html>