什么是JavaScript中的文档及其范围? [英] What is document in JavaScript and what is its scope?

查看:75
本文介绍了什么是JavaScript中的文档及其范围?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

var document = "temp";

function showDocument()
{
    alert(document); // temp or HTML DOM Document
}

为我显示HTML DOM文档应该是这样的。是对象,保留关键字,只读对象?

It showed "HTML DOM Document" for me, which should be the case. Is it an object, reserved keyword, read-only object?

如果它是一个对象,它应该是可编辑的。如果它是一个保留关键字,JavaScript应该会引发错误/异常。如果它是只读的,我该怎么修改只能通过文档访问的DOM本身?

If it's an object, it should be editable. If it's a reserved keyword, JavaScript should throw an error/exception. If it's read-only, how can I modify the DOM itself which is accessible through document only?

推荐答案

它是全局(窗口)对象的只读属性。它的值是表示当前HTML / XML /任何加载到窗口中的文件的本地对象。

It's a read-only property of the global (window) object. Its value is a native object representing the current HTML/XML/whatever document loaded into the window.

要修改DOM,请使用 DOM操作API

To modify the DOM, use DOM manipulation APIs.

编辑—为了澄清,窗口对象的document属性(或者,如果您愿意,全局变量名为document)是本身不可变,它的值不能被JavaScript改变。然而,该值是对象的一个​​引用,一种可以各种方式进行变形的对象。

edit — to clarify, the "document" property of the window object (or, if you prefer, the global variable called "document") is itself immutable, and its value cannot be changed by JavaScript. The value, however, is a reference to an object, an object that is mutable in all sorts of ways.

这篇关于什么是JavaScript中的文档及其范围?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆