執行 ❯
建立您
自己的
網站
×
更改方向
儲存程式碼
更改主題,深色/淺色
前往Spaces
<!DOCTYPE html> <html> <body> <p>Use the HTML DOM to assign an "onkeypress" event to an input element.</p> <p>Press a key inside the text field to set a red background color.</p> <input type="text" id="demo"> <script> document.getElementById("demo").onkeypress = function() {myFunction()}; function myFunction() { document.getElementById("demo").style.backgroundColor = "red"; } </script> </body> </html>