BootWiki教程网
源代码:
点击运行
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>BootWiki 教程网</title> <script> function setStyle(x) { document.getElementById(x).style.background="yellow"; } </script> </head> <body> <p>当输入域获得焦点时setStyle函数被触发。该函数改变输入域的背景色。</p> 第一个名字: <input id="fname" onfocus="setStyle(this.id)" type="text"><br> 最后一个名字: <input id="lname" onfocus="setStyle(this.id)" type="text"> </body> </html>
运行结果