본문 바로가기

개발하자/jQuery

blur

<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script>
$(document).ready(function(){
    $("input").focus(function(){        //포커스를 얻었을때
        $(this).css("background-color", "#cccccc");    //바탕을 회색으로 바꿈
    });
    $("input").blur(function(){        //포커스를 잃었을때
        $(this).css("background-color", "#ffffff");    //바탕을 다시 흰색으로 바꿈
    });
});
</script>
</head>
<body>

Name: <input type="text" name="fullname"><br>
Email: <input type="text" name="email">

</body>
</html>