Please note, this is a STATIC archive of website developer.mozilla.org from November 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

document.width

已废弃
This feature is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it.

Gecko 6.0 note
(Firefox 6.0 / Thunderbird 6.0 / SeaMonkey 2.3)

从Gecko 6.0开始,不再支持document.width,请使用document.body.clientWidth来代替.查看element.clientWidth.

概述

返回当前文档中的<body>元素的宽度,单位为像素.Internet Explorer不支持该属性.

语法

pixels = document.width;

示例

function init() {
    alert("当前文档的宽度为 " + document.width + " 像素.");
}

请使用下面的属性来替代该属性

document.body.clientWidth              /* <body>元素的宽度 */
document.documentElement.clientWidth   /* <html>元素的宽度 */
window.innerWidth                      /* window的宽度 */

规范

DOM Level 0 不属于任何标准.

相关链接

文档标签和贡献者

 此页面的贡献者: teoli, khalid32, ziyunfei
 最后编辑者: khalid32,