示例您可以尝试运行以下代码来实现 onfocus 属性 -
<!doctype html><html> <body> <p>enter subject name below,</p> subject: <input type = "text" id = "sname" onfocus = "display(this.id)"> <br> <script> function display(val) { document.getelementbyid(val).style.background = "blue"; } </script> </body></html>
以上就是当html元素获得焦点时执行脚本?的详细内容。