HTML DOM readyState 属性
2016-02-23 16:03
666 查看
readyState 属性返回当前文档的状态(载入中……)。
该属性返回以下值:
uninitialized - 还未开始载入
loading - 载入中
interactive - 已加载,文档与用户可以开始交互
complete - 载入完成
语法
document.readyState
浏览器支持
Internet ExplorerFirefoxOperaGoogle ChromeSafari
所有主要浏览器都支持 readyState 属性
if(document.addEventListener){
function DOMContentLoaded(){
$("#status").text("DOM is ready now!");
}
document.addEventListener( "DOMContentLoaded", DOMContentLoaded, false );
}
window.onload=function(){
$("#status").text("DOM is ready AND wondow.onload is excute!");
}
这个属性是只读的,传回值有以下的可能:
0-UNINITIALIZED:XML 对象被产生,但没有任何文件被加载。
1-LOADING:加载程序进行中,但文件尚未开始解析。
2-LOADED:部分的文件已经加载且进行解析,但对象模型尚未生效。
3-INTERACTIVE:仅对已加载的部分文件有效,在此情况下,对象模型是有效但只读的。
4-COMPLETED:文件已完全加载,代表加载成功。
范 例
alert("The readyState property is " + xmlDoc.readyState);
<script language="javascript">
if (document.readyState=="complete")
{
AdjustImageSize();
}
else
{
document.onreadystatechange = function()
{
if (document.readyState == "complete")
{
AdjustImageSize();
}
}
}
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;
}
els
4000
e
{
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;
}
</script>
该属性返回以下值:
uninitialized - 还未开始载入
loading - 载入中
interactive - 已加载,文档与用户可以开始交互
complete - 载入完成
语法
document.readyState
浏览器支持
Internet ExplorerFirefoxOperaGoogle ChromeSafari
所有主要浏览器都支持 readyState 属性
if(document.addEventListener){
function DOMContentLoaded(){
$("#status").text("DOM is ready now!");
}
document.addEventListener( "DOMContentLoaded", DOMContentLoaded, false );
}
window.onload=function(){
$("#status").text("DOM is ready AND wondow.onload is excute!");
}
这个属性是只读的,传回值有以下的可能:
0-UNINITIALIZED:XML 对象被产生,但没有任何文件被加载。
1-LOADING:加载程序进行中,但文件尚未开始解析。
2-LOADED:部分的文件已经加载且进行解析,但对象模型尚未生效。
3-INTERACTIVE:仅对已加载的部分文件有效,在此情况下,对象模型是有效但只读的。
4-COMPLETED:文件已完全加载,代表加载成功。
范 例
alert("The readyState property is " + xmlDoc.readyState);
<script language="javascript">
if (document.readyState=="complete")
{
AdjustImageSize();
}
else
{
document.onreadystatechange = function()
{
if (document.readyState == "complete")
{
AdjustImageSize();
}
}
}
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;
}
els
4000
e
{
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;
}
</script>
相关文章推荐
- .net 清除单条资讯html格式
- 阻止html页面在手机上显示时点击form表单控件页面放大
- 不可不知的HTML优化技巧
- 浏览器加载和渲染html的顺序
- HTML代码书写规范指南
- HTML 5基础 — 熟悉Canvas
- 如何选择Html.RenderPartial和Html.RenderAction
- Html中的map标签
- MVC————扩展方法MvcHtmlString
- 使用 markdownj 将 markdown 转换为 html
- Chap 09 HTML使用框架结构
- HTML搜索引擎优化
- 浏览器加载、渲染html的顺序和页面优化
- HTML标记之Form表单
- HTML常用标签
- HtmlParser中的各种Filter(1)
- HTML标记之a标签
- Html标签列表【转】
- 初识HTML
- HtmlParser中的各种Filter