zoukankan      html  css  js  c++  java
  • 焦点事件

    获得焦点事件(onfocus)是当某个元素获得焦点时触发事件处理程序。
    失去焦点事件(onblur)是当前元素失去焦点时触发事件处理程序。
    一般情况下,这两个事件是同时使用的。
     
    二 应用
    文本框获得焦点时改变背景颜色
    本示例是在用户选择页面中的文本框时,改变文本框的背景颜色,当选择其他文本框时,将失去焦点的文本框背景颜色恢复原始状态。
     
    三 代码
    <table align="center" width="337" height="204" border="0">
    <tr>
    <td width="108">用户名:</td>
    <td width="213"><form name="form1" method="post" action="">
    <input type="text" name="textfield" onfocus="txtfocus()" onBlur="txtblur()">
    </form></td>
    </tr>
    <tr>
    <td>密码:</td>
    <td><form name="form2" method="post" action="">
    <input type="text" name="textfield2" onfocus="txtfocus()" onBlur="txtblur()">
    </form></td>
    </tr>
    <tr>
    <td>真实姓名:</td>
    <td><form name="form3" method="post" action="">
    <input type="text" name="textfield3" onfocus="txtfocus()" onBlur="txtblur()">
    </form></td>
    </tr>
    <tr>
    <td>性别:</td>
    <td><form name="form4" method="post" action="">
    <input type="text" name="textfield5" onfocus="txtfocus()" onBlur="txtblur()">
    </form></td>
    </tr>
    <tr>
    <td>邮箱:</td>
    <td><form name="form5" method="post" action="">
    <input type="text" name="textfield4" onfocus="txtfocus()" onBlur="txtblur()">
    </form></td>
    </tr>
    </table>
    <script language="javascript">
    <!--
    function txtfocus(event){ //当前元素获得焦点
    var e=window.event;
    var obj=e.srcElement; //用于获取当前对象的名称
    obj.style.background="#FFFF66";
    }
    function txtblur(event){ //当前元素失去焦点
    var e=window.event;
    var obj=e.srcElement;
    obj.style.background="FFFFFF";
    }
    //-->
    </script>
    ---------------------
    作者:chengqiuming
    来源:CSDN
    原文:https://blog.csdn.net/chengqiuming/article/details/70140140
    版权声明:本文为博主原创文章,转载请附上博文链接!

  • 相关阅读:
    利用Abot爬虫和visjs 呈现漫威宇宙
    Abot 爬虫分析-整体结构
    利用Abot 抓取博客园新闻数据
    sftp配置多个用户权限的问题
    十三、Vue中的computed属性
    十二、react-reudx之@connect 摆脱redux的繁琐操作
    十一、微信小程序-var、let、const用法详解
    十、es6之扩展运算符 三个点(...)
    九、小程序 Redux详解与在小程序中怎么使用(action和reducers)
    八、wepy代码规范
  • 原文地址:https://www.cnblogs.com/jiaxinchao/p/10174862.html
Copyright © 2011-2022 走看看