2012-06-03 17 views
11

在javascript的範圍內,指的是HTMLDocumentHTMLElement會在IE8上產生錯誤。什麼是IE對HTMLDocument和HTMLElement的影響

我得到的錯誤是「HTMLElement未定義」。

讓JS與本瀏覽器的本地DOM對象進行交互的方式是什麼?

+0

http://stackoverflow.com/questions/8868004/htmlelement-is-undefined-in-ie8-an-alternative – mplungjan

+0

@mplungjan - 這是undelated,因爲我不是要求給定的元素,而是關於DOM核心API。 –

回答

13

在IE8中,您必須使用ElementHTMLDocument類。在IE7中......沒有什麼,因爲IE7對於標準來說太糟糕了。你必須依靠jQuery或其他包裝DOM元素的框架。

在我自己的框架,我做這個簡單的檢查:

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

你要知道,這不是對IE7和更低的框架。

+2

我剛剛測試過的又是IE8上的,Element和Document都是未定義的。 –

+3

@TruryBarYochay在IE8中定義了'Element'。如果沒有,那是因爲你處於兼容模式。關於'Document',它實際上是'HTMLDocument'。 – MaxArt

+0

回答相應標記;-) –

相關問題