onfous and onblur的使用

本文最后修改于 592 天前,部分内容可能已经过时!

时间:2018.11.16

类型:javascript

关键代码:

用户名:<input type="text" id="fname" onfocus="setStyle(1,this.id)"  onblur="setStyle(2,this.id)">
<br>
密&nbsp;码:<input type="text" id="lname" onfocus="setStyle(1,this.id)" onblur="setStyle(2,this.id)">

<script type="text/javascript">
    function setStyle(a,id) {
        if (a == 1) {
            document.getElementById(id).style.background = "#f60";
        }else if(a == 2) {
            document.getElementById(id).style.background = "white";
        }
    }
</script>

!!!
<p>
    <strong>实际效果:</strong>
</p>
<p>
    用户名:<input type="text" id="fname" onfocus="setStyle(1,this.id)" onblur="setStyle(2,this.id)"/><br/>密&nbsp;码:<input type="text" id="lname" onfocus="setStyle(1,this.id)" onblur="setStyle(2,this.id)"/>
</p><script type="text/javascript">function setStyle(a,id) {
    if (a == 1) {
        document.getElementById(id).style.background = "#f60";
    }else if(a == 2) {
        document.getElementById(id).style.background = "white";
    }
  }</script>
Tags:none
上一篇
打赏
下一篇

添加新评论