<html>
<body>
<p>当其中一个输入字段获得焦点时,将触发一个函数。 该函数更改输入字段的背景颜色。</p>
First name: <input type="text" id="fname" onfocus="myFunction(this.id)"><br>
Last name: <input type="text" id="lname" onfocus="myFunction(this.id)">
<script>
function myFunction(x) {
document.getElementById(x).style.background = "yellow";
}
</script>
</body>
</html>