Thuộc tính event.returnValue (trên đối tượng Event) cho phép lấy hoặc đặt việc sự kiện hiện tại có bị hủy bỏ hay không. Giá trị true = sự kiện diễn ra bình thường, false = hủy sự kiện.
Cú pháp
Lấy: event.returnValue
Đặt: event.returnValue = true | false
Ví dụ
<!DOCTYPE html>
<html>
<head>
<style>
body { color: #000; height: 100vh; background-color: #FBAB7E; background-image: linear-gradient(62deg, #FBAB7E 0%, #F7CE68 100%); text-align: center; }
input { width: 200px; height: 2rem; }
.msg { font-size: 1.5rem; }
</style>
</head>
<body>
<h1>Demo event.returnValue</h1>
<input type="text" placeholder="Nhập tên (focus để test)" onfocus="showReturnValue(event)">
<p class="msg"></p>
<script>
function showReturnValue(event) {
document.querySelector('.msg').innerHTML =
'Giá trị returnValue của onfocus: ' + event.returnValue;
}
</script>
</body>
</html>
Kết quả
Click vào ô input (focus) → hiển thị true (mặc định sự kiện không bị hủy).
Lưu ý: Thuộc tính này chủ yếu dùng trong IE cũ. Tiêu chuẩn hiện đại dùng event.preventDefault() để hủy hành vi mặc định, event.defaultPrevented để kiểm tra.