分享

网页中document.readyState几种状态 (下载完成等)及示例

 北极星管 2017-02-21

document.readyState几种状态及示例 

说 明 

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

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


document.readyState几种状态及示例 - gaoyusi - My code life<script language="javascript">
document.readyState几种状态及示例 - gaoyusi - My code life
document.readyState几种状态及示例 - gaoyusi - My code life
if (document.readyState=="complete")
{
        AdjustImageSize();
}

document.readyState几种状态及示例 - gaoyusi - My code life
else
{
        document.onreadystatechange 
= function()
        
{
           
                
if (document.readyState == "complete")
                
{
                        AdjustImageSize();
                }

        }

}

document.readyState几种状态及示例 - gaoyusi - My code life
document.readyState几种状态及示例 - gaoyusi - My code life
function AdjustImageSize()
{
        
var imageWidth = document.all["SendPic"].width;
        
var imageHeight = document.all["SendPic"].height;
        
        
if (imageWidth == 0 && imageHeight == 0)
        
{
                document.write (
"图片下载失败,请刷新!");
                
return;
        }

        
        
if (imageWidth > 160 || imageHeight > 160)
        
{
                
if (imageWidth > imageHeight)
                
{
                        k 
= 160 / imageWidth;
                        imageHeight 
= imageHeight * k;
                        imageWidth 
= 160;
                }

                
else
                
{
                        k 
= 160 / imageHeight;
                        imageWidth 
= imageWidth * k;
                        imageHeight 
= 160;
                }

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

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

document.readyState几种状态及示例 - gaoyusi - My code life
</script>

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多