Định nghĩa và sử dụng .focusout() trong jQuery

.focusout(): Xử lý một sự kiện "focusout" (xác nhận thoát khỏi focus).

Cấu trúc .focusout() trong jQuery

Đã được thêm vào từ phiên bản 1.4

.focusout(function(){...});
$('p').focusout(function(){
    $(this).find('input').css('color','#ccc');
});

.focusout(function(){...});

Html viết:

<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Tiêu đề</title>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<style>
input { color: #ccc; }
</style>
<script>
$(function(){
    $('p').focusin(function(){
        $(this).find('input').css('color','#000');
    }).focusout(function(){
        $(this).find('input').css('color','#ccc');
    });
});
</script>
</head>

<body>
<p><input type="text" value="Nhập text" />
<p><input type="text" value="Nhập text" />
</body>
</html>

Hiển thị trình duyệt:

Click vào trường input sau đó click ra bên ngoài (thoát khỏi focus) để thấy kết quả.

Viết câu trả lời

Drop Images

0 Bình luận