jQuery: focus() method
Khi người dùng click chuột, dùng phím tab hoặc dùng phím tắt để focus vào một phần tử HTML thì phương thức focus() sẽ được kích hoạt.
Ví dụ:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="http://ajax.googleapis. com/ajax/libs/jquery/1.11.0 /jquery.min.js">
</script>
<script>
$(function(){
$("input").focus(function(){
$(this).css("background", "red");
});
});
</script>
<style>
input{
width:40%;
color:white;
}
</style>
</head>
<body>
<input accesskey="C" placeholder="Nhấn chuột vào tôi, nhấn phím Tab, hoặc nhấn tổ hợp phím 'Alt+C' => Tôi đỏ">
</body>
</html>