Firefox Javascript:为什么.all不工作? [英] Firefox Javascript: Why does .all not work?

查看:129
本文介绍了Firefox Javascript:为什么.all不工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在IE中,我可以这样做:

  var x = document.getElementById(header); 

alert(x.all [0] .tagName);

如果我在Firefox中尝试,我会得到错误all is undefined。



什么是IE的 .all 属性的Firefox等价物?

解决方案 .all 是微软特定于DOM的扩展,并且不受任何其他浏览器支持(Opera除外,谁来模拟它,以提高与IE编写的站点的兼容性)。



你可以使用像 x.children x.childNodes x.getElementById() x.getElementsByTagName 引用树中当前元素之下的元素,具体取决于您的使用情况。我怀疑在这种情况下 x.children 就是你要的。


In IE, I can go like:

var x = document.getElementById("header");

alert(x.all[0].tagName);

If I try that in Firefox, I get the error "all is undefined".

What is the Firefox equivalent of IE's .all property?

解决方案

.all is a Microsoft-specific extension to the DOM, and is not supported by any other browsers (except Opera, I believe, who simulate it in order to improve compatibility with sites written for IE).

You can use things like x.children and x.childNodes, or x.getElementById() and x.getElementsByTagName() to reference elements below the current one in the tree, depending on your usage. I suspect in this case x.children is what you're after.

这篇关于Firefox Javascript:为什么.all不工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆