Firefox Javascript:为什么.all不工作? [英] Firefox Javascript: Why does .all not work?
问题描述
var x = document.getElementById(header);
alert(x.all [0] .tagName);
如果我在Firefox中尝试,我会得到错误all is undefined。
什么是IE的 .all
属性的Firefox等价物?
你可以使用像 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屋!