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