源代碼
點擊運行
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>教程</title> </head> <head> <script> function myFunction(x){ x.style.background="yellow"; } </script> </head> <body> 輸入你的名字: <input type="text" onfocus="myFunction(this)"> <p>當輸入框獲取焦點時,修改背景色(background-color屬性) 將被觸發。</p> </body> </html>
運行結果