jquery对于输入框得到与失去焦点时的处理方法

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title></title>
    </head>
    <body>
        <p>帐号:&ensp;<input type="text" name="" id="" value="" /></p>
        <p>密码:&ensp;<input type="text" name="" id="" value="" /></p>
    </body>
</html>
<script src="jquery-3.4.1.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
    // focus() 输入框得到焦点时的处理
    // bulr()  输入框失去焦点时的处理
    $(function() {
        $('input:first').focus(function() {
            $(this).css('background', '#eee');
        });
        $('input:first').blur(function() {
            $(this).css('background', '#fff');
        });
        $('input:enabled').focus(function() {
            $(this).css('background', '#eee');
        });
        $('input:enabled').blur(function() {
            $(this).css('background', '#fff');
        });
    });
</script>

猜你喜欢

转载自www.cnblogs.com/li1234567980/p/11746985.html