Thuộc tính readyState trong HTML DOM trả về trạng thái tải (loading status) của tài liệu HTML hiện tại. Các giá trị có thể là: loading, interactive, complete.
Cú pháp
document.readyState
Ví dụ
Ví dụ sử dụng thuộc tính readyState:
<!DOCTYPE html>
<html>
<head>
<style>
html { height: 100%; }
body { text-align: center; color: #fff; background: #ff7f5094; height: 100%; }
p { font-weight: 700; font-size: 1.2rem; }
.btn { background: #0197F6; border: none; height: 2rem; border-radius: 2px; width: 35%; margin: 2rem auto; display: block; color: #fff; outline: none; cursor: pointer; }
.show { font-size: 1.5rem; }
</style>
</head>
<body>
<h1>Demo thuộc tính readyState DOM</h1>
<p>Tài liệu hiện tại đã sẵn sàng chưa?</p>
<button onclick="showStatus()" class="btn">Kiểm tra trạng thái</button>
<div class="show"></div>
<script>
function showStatus() {
document.querySelector(".show").innerHTML = "Vâng, tài liệu hiện tại của bạn đang tải <strong>" + document.readyState + "</strong>.";
}
</script>
</body>
</html>
Kết quả
Nhấn nút Kiểm tra trạng thái để kiểm tra trạng thái tải của tài liệu HTML hiện tại.