什么是IE对HTMLDocument和HTMLElement

Tzu*_*hay 12 html javascript internet-explorer dom

在javascript的范围内,引用HTMLDocumentHTMLElement引发IE8上的错误.

我得到的错误是"HTMLElement未定义".

让JS与此浏览器的本机DOM对象进行交互的方法是什么?

Max*_*Art 13

在IE8中,您必须使用ElementHTMLDocument类.在IE7中......没什么,因为IE7标准很糟糕.您必须依赖jQuery或其他包装DOM元素的框架.

在我自己的框架中,我做了这个简单的检查:

var elementPrototype = typeof HTMLElement !== "undefined"
        ? HTMLElement.prototype : Element.prototype;
Run Code Online (Sandbox Code Playgroud)

请注意,它不是IE7及更低版本的框架.

  • @TzuryBarYochay在IE8中,定义了`Element`.如果没有,那是因为你处于兼容模式.关于`Document`,它实际上是`HTMLDocument`. (3认同)
  • 我刚刚在IE8上进行了测试,并且元素和文档都未定义. (2认同)