JS点击文本框改变背景颜色

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

JS点击文本框改变背景颜色

kiss_scarecrow   2022-09-28 我要评论

代码如下:

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8" />
        <title>文本框获焦点改变背景颜色</title>
    </head>
    <body>
        <table align="center"width="337" height="204"border=()>
        <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="#FF9966";
            }
            function txtblur(event){
                var e=window.event;
                var obj=e.srcElement;
                obj.style.background="#FFFFFF";
            }
            //-->
        </script>
        
    </body>
</html>

结果如图:

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们