用 document.readyState == "complete" 判断页面是否加载完成。

本文介绍了XML文档加载的不同状态及其含义,包括未初始化、加载中、已加载、交互式及完成等阶段,并通过示例展示了如何使用JavaScript判断这些状态。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

传回XML 文件资料的目前状况。  
基本语法
intState = xmlDocument.readyState;
 
说 明

这个属性是只读的,传回值有以下的可能:

0-UNINITIALIZED:XML 对象被产生,但没有任何文件被加载。
1-LOADING:加载程序进行中,但文件尚未开始解析。
2-LOADED:部分的文件已经加载且进行解析,但对象模型尚未生效。
3-INTERACTIVE:仅对已加载的部分文件有效,在此情况下,对象模型是有效但只读的。
4-COMPLETED:文件已完全加载,代表加载成功。
 
 
范 例
alert("The readyState property is " + xmlDoc.readyState);


None.gif<script language="javascript">
None.gif
None.gif
if (document.readyState=="complete")
ExpandedBlockStart.gifContractedBlock.gif
dot.gif{
InBlock.gif        AdjustImageSize();
ExpandedBlockEnd.gif}

None.gif
else
ExpandedBlockStart.gifContractedBlock.gif
dot.gif{
InBlock.gif        document.onreadystatechange 
= function()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif           
InBlock.gif                
if (document.readyState == "complete")
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                        AdjustImageSize();
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif        }

ExpandedBlockEnd.gif}

None.gif
None.gif
function AdjustImageSize()
ExpandedBlockStart.gifContractedBlock.gif
dot.gif{
InBlock.gif        
var imageWidth = document.all["SendPic"].width;
InBlock.gif        
var imageHeight = document.all["SendPic"].height;
InBlock.gif        
InBlock.gif        
if (imageWidth == 0 && imageHeight == 0)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif                document.write (
"图片下载失败,请刷新!");
InBlock.gif                
return;
ExpandedSubBlockEnd.gif        }

InBlock.gif        
InBlock.gif        
if (imageWidth > 160 || imageHeight > 160)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif                
if (imageWidth > imageHeight)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                        k 
= 160 / imageWidth;
InBlock.gif                        imageHeight 
= imageHeight * k;
InBlock.gif                        imageWidth 
= 160;
ExpandedSubBlockEnd.gif                }

InBlock.gif                
else
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                        k 
= 160 / imageHeight;
InBlock.gif                        imageWidth 
= imageWidth * k;
InBlock.gif                        imageHeight 
= 160;
ExpandedSubBlockEnd.gif                }

InBlock.gif                
InBlock.gif                document.all[
"ImgResized"].value = "1";
ExpandedSubBlockEnd.gif        }

InBlock.gif        
InBlock.gif        document.all[
"SendPic"].width = imageWidth;
InBlock.gif        document.all[
"SendPic"].height = imageHeight;
InBlock.gif        
InBlock.gif        document.all[
"ImgWidth"].value = imageWidth;
InBlock.gif        document.all[
"ImgHeight"].value = imageHeight;
ExpandedBlockEnd.gif}

None.gif
</script>
None.gif
None.gif
//////////////////////////////////////////////////////////// // ============= micro HTML5 library ===================== // @author zhongweiChen // last update: Mach 10, 2025 // Released under the MIT license //////////////////////////////////////////////////////////// // ===== ge1doot global ===== var ge1doot = ge1doot || { json: null, screen: null, pointer: null, camera: null, loadJS: function (url, callback, data) { if (typeof url == "string") url = [url]; var load = function (src) { var script = document.createElement("script"); if (callback) { if (script.readyState){ script.onreadystatechange = function () { if (script.readyState == "loaded" || script.readyState == "complete"){ script.onreadystatechange = null; if (--n === 0) callback(data || false); } } } else { script.onload = function() { if (--n === 0) callback(data || false); } } } script.src = src; document.getElementsByTagName("head")[0].appendChild(script); } for (var i = 0, n = url.length; i < n; i++) load(url[i]); } } // ===== html/canvas container ===== ge1doot.Screen = function (setup) { ge1doot.screen = this; this.elem = document.getElementById(setup.container) || setup.container; this.ctx = this.elem.tagName == "CANVAS" ? this.elem.getContext("2d") : false; this.style = this.elem.style; this.left = 0; this.top = 0; this.width = 0; this.height = 0; this.cursor = "default"; this.setup = setup; this.resize = function () { var o = this.elem; this.width = o.offsetWidth; this.height = o.offsetHeight; for (this.left = 0, this.top = 0; o != null; o = o.offsetParent) { this.left += o.offsetLeft; this.top += o.offsetTop; } if (this.ctx) { this.elem.width = this.width; this.elem.height = this.height; } this.setup.resize && this.setup.resize(); } this.setCursor = function (type) { if (type !== this.cursor && 'ontouchstart' in window === false) { this.
03-11
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值