源代码
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>编程字典</title> </head> <body> <p>当你在输入框按下按键再释放时,会触发该函数。该函数会将小写转换为大写.</p> 输入你的姓名: <input type="text" id="fname" onkeyup="myFunction()"> <script> function myFunction() { var x = document.getElementById("fname"); x.value = x.value.toUpperCase(); } </script> </body> </html>
运行结果