当编写要在 IE 中执行的 javascript 函数时,我可以编写如下内容
var myObj = document.getElementByID('myTable');
var firstRow = myObj.rows[0];
var allRowObjects = firstRow.all;
在 IE 之外,“.all”将无法识别,因此在其他浏览器中运行时我会遇到问题。我找到了对 querySelectorAll("*") 函数的引用,这似乎是获取相同节点列表的环境安全方法,但这是“.all”在做什么吗?是否有我应该使用的不同模拟,我在哪里可以找到关于“所有”的文档?
最佳答案
Microsoft actually admits .all
不是任何标准的一部分,从 IE 11 开始不再受支持,建议您改用 getElementById
。
The all collection includes one element object for each valid HTML tag. If a valid tag has a matching end tag, both tags are represented by the same element object.
The collection returned by the document's all collection always includes a reference to the HTML, HEAD, and TITLE objects regardless of whether the tags are present in the document.
If the BODY tag is not present, but other HTML tags are, a BODY object is added to the all collection. If the document contains invalid or unknown tags, the collection includes one element object for each. Unlike valid end tags, unknown end tags are represented by their own element objects. The order of the element objects is the HTML source order. Although the collection indicates the order of tags, it does not indicate hierarchy.
The name property only applies to some elements such as form elements. If the vIndex is set to a string matching the value of a name property in an element that the name property does not apply, then that element will not be added to the collection.
关于javascript - 是否有 "all"元素集合的非 IE 等价物?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20055045/