<html>
<body>
<p>本例使用 addEventListener() 方法将 "keyup" 事件附加到 input 元素。</p>
<p>在文本字段内按键并松开它可设置红色背景颜色。</p>
请输入您的姓名:<input type="text" id="fname">
<script>
document.getElementById("fname").addEventListener("keyup", myFunction);
function myFunction() {
var x = document.getElementById("fname");
x.value = x.value.toUpperCase();
}
</script>
</body>
</html>