鼠标点文本框里是黄色,鼠标离开是其他颜色,或者变回原来的颜色,onfocus,onblur,js

鼠标点文本框里是黄色,鼠标离开是其他颜色,或者变回原来的颜色

<html>
<head>
<script type="text/javascript">
function setStyle(x)
{
document.getElementById(x).style.background="yellow"
}
function setStyle2(x)
{
document.getElementById(x).style.background="blue"
}
function setStyle3(x)
{
document.getElementById(x).style.background=""
}
</script>
</head>

<body>

First name: <input type="text"
onfocus="setStyle(this.id)" onblur="setStyle2(this.id)" id="fname" />
<br />
Last name: <input type="text"
onfocus="setStyle(this.id)" onblur="setStyle3(this.id)" id="lname" />

</body>
</html>

 

 

黑色头发  http://heisetoufa.iteye.com

你可能感兴趣的:(JavaScript,html)