js 中HTML的 onkeycode 和onkeydown属性事件

<!DOCTYPE html>
<html>
<head>
<script>
function displayResult()
{
var x=document.getElementById("fname");
x.value=x.value.toUpperCase();
}
</script>
</head>
<body>

<p>当用户在输入字段中按下按键时触发函数。此函数把字符转换为大写。</p>

请输入您的姓名(英文字符):<input type="text" id="fname" onkeyup="displayResult()">

</body>
</html>

onkyedown属性事件与onkeyup一样,只不过是:一个按键松开执行代码,一个按键按下执行代码。

原文地址:https://www.cnblogs.com/mark5/p/10947594.html