菜单切换
FACESOHO知行者
心灵
记录
远方
赞赏工具
源代码:
点击运行
保存
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>小鸟启蒙(facesoho.com)</title> <script> function setStyle(x) { document.getElementById(x).style.background="yellow"; } </script> </head> <body> <p>当输入域获得焦点时setStyle函数被触发。该函数改变输入域的背景色。</p> 第一个名字: <input type="text" id="fname" onfocus="setStyle(this.id)"><br> 最后一个名字: <input type="text" id="lname" onfocus="setStyle(this.id)"> </body> </html>
运行结果