Heim  >  Artikel  >  Web-Frontend  >  再谈ie和firefox下的document.all属性_javascript技巧

再谈ie和firefox下的document.all属性_javascript技巧

WBOY
WBOYOriginal
2016-05-16 18:44:011104Durchsuche

例如下面的代码:

复制代码 代码如下:







在IE浏览器会输出 “this is a IE”;
而在firefox浏览器中会输出"this is a Mozilla"。

但这样是不能直接就认为在 firefox中 是不支持 document.all属性方法的。

下面一段代码,在IE和firefox浏览器下都运行正常
复制代码 代码如下:








这是因为较新FF对all做了特殊处理,JS在招行过程中检测到只有单独的all属性是,就会返回JSVAL_VOID(也就是false)值;
当JS在招行过程中检测到形如'if (o.p)...' or '(o.p) ?...:...', 则回返回一个HTMLCOLLECTION对像.
而在GOOGLE浏览器中,则对all有双重分处,既是一个COLLECTION又是一个JS VOID(false)值.
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn