Thuộc tính sự kiện returnValue trong HTML trả về và sửa đổi xem sự kiện hiện tại có bị hủy hay không.
Cú pháp
Sau đây là cú pháp -
1. Trả lại giá trị returnValue
event.returnValue
2. Thêm returnValue
event.returnValue=”true | false”
Hãy để chúng tôi xem một ví dụ về thuộc tính sự kiện returnValue trong HTML−
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>HTML returnValue Event Property Demo</h1>
<input type="text" placeholder="Enter your name" onfocus="show(event)">
<p class="msg"></p>
<script>
function show(event) {
document.querySelector('.msg').innerHTML = 'Is onfocus event is active on above input field? ' + event.returnValue;
}
</script>
</body>
</html> Đầu ra
Bây giờ, hãy thử nhập giá trị vào trường đầu vào để làm cho nó tập trung để hiển thị giá trị của thuộc tính sự kiện returnValue.