HTML DOM readyState 属性
htmlweb developmentfront end technology更新于 2025/8/28 17:48:17
DOM readyState 属性返回当前 HTML 文档的加载状态。
语法
以下是语法 −
document.readyState
示例
让我们看一个 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>DOM readyState Property Demo</h1>
<p>Is current document ready?</p>
<button onclick="showStatus()" class="btn">Check Status</button>
<div class="show"></div>
<script>
function showStatus() {
document.querySelector(".show").innerHTML="Yes, your current document's loading is " + "" + document.readyState +".";
}
</script>
</body>
</html>
输出
这将产生以下输出 −

点击"检查状态"按钮检查当前 HTML 文档的加载状态。

相关文章
有用资源
html 参考教程 - 该教程包含有关 html 的更多信息:https://www.cainiaomax.com/html/

