源代码
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>编程字典</title> </head> <body> <p>当用户在输入框中按下按键时,函数被触发</p> <input type="text" onkeypress="myFunction()"> <script> function myFunction() { alert("你在输入框内按下了按键"); } </script> </body> </html>
运行结果