<html>
<body>
<p>当您输入输入字段时,会触发将背景颜色设置为黄色的函数。当您离开输入字段时,会触发将背景颜色设置为红色的函数。</p>
请输入姓名:<input type="text" id="myInput" onfocus="focusFunction()" onblur="blurFunction()">
<script>
function focusFunction() {
// Focus = 将输入的背景颜色更改为黄色
document.getElementById("myInput").style.background = "yellow";
}
function blurFunction() {
// No focus = 将输入的背景颜色更改为红色
document.getElementById("myInput").style.background = "red";
}
</script>
</body>
</html>