【问题标题】:What's IE take on HTMLDocument and HTMLElementIE 对 HTMLDocument 和 HTMLElement 有何影响
【发布时间】:2012-06-07 18:46:18
【问题描述】:

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

我得到的错误是“HTMLElement is undefined”。

JS 与本浏览器的原生 DOM 对象交互的方式是什么?

【问题讨论】:

标签: javascript html internet-explorer dom


【解决方案1】:

在 IE8 中,您必须使用 ElementHTMLDocument 类。在 IE7 中……什么都没有,因为 IE7 对标准来说太糟糕了。您必须依赖 jQuery 或其他包装 DOM 元素的框架。

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

var elementPrototype = typeof HTMLElement !== "undefined"
        ? HTMLElement.prototype : Element.prototype;

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

【讨论】:

  • 我刚刚在 IE8 上再次测试过,Element 和 Document 都未定义。
  • @TzuryBarYochay 在 IE8 中,定义了 Element。如果不是,那是因为您处于兼容模式。关于Document,其实是HTMLDocument
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-02-17
  • 1970-01-01
  • 2011-03-17
  • 2011-03-16
  • 2013-11-16
  • 1970-01-01
  • 2018-07-17
相关资源
最近更新 更多