W3School TIY Editor
W3School 在线教程
改变方向
暗黑模式
运行代码
<!DOCTYPE html> <html> <body> <p>本例演示如何将 "onkeypress" 事件分配给 input 元素。</p> <p>Press a key inside the text field to set a red background color.</p> <input type="text" id="demo" onkeypress="myFunction()"> <script> function myFunction() { document.getElementById("demo").style.backgroundColor = "red"; } </script> </body> </html>