2011-09-18 84 views
4

在我的网页的一个不支持的,我使用的JavaScript的下面一行:方法compareDocumentPosition只有在IE9

return !!(a.compareDocumentPosition(b) & 16); 

然而,只有在IE9,我收到以下错误:

Object doesn't support property or method 'compareDocumentPosition'

其他浏览器正常工作。有谁知道可用的修复或解决方法吗?

+1

查看http://ejohn.org/blog/comparing-document-position/获取IE解决方案。 – pimvdb

+1

Internet Explorer仅在IE9模式下支持'compareDocumentPosition'。确保你在标记的开始有'<!doctype html>',并且'document.documentMode'返回'9'。 – duri

+1

@pimvdb IE9支持'compareDocumentPosition(...)'(参见[msdn](http://msdn.microsoft.com/en-us/library/ff975125%28v=vs.85%29.aspx))。您的网站是IE少于版本9的解决方法。 – scessor

回答

1

Internet Explorer supports compareDocumentPosition only in IE9 mode. Make sure you have at the beginning of your markup and document.documentMode returns 9