javascript - 是否有 "all"元素集合的非 IE 等价物?

标签 javascript internet-explorer

当编写要在 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/

相关文章:

JavaScript 控制台没有正确的值

css - 为什么 Wordpress 不为 Internet Explorer 9 分配 <html id ="ei9"...?

html - 在 IE 7/8 中渲染 svg

javascript - 强制 attr=title 弹出 on 元素

javascript - 如何从 http ://cmsaspnet. com/forum.aspx 页面创建一个像按钮一样的白绿色按钮?

javascript - 你能解释一下这个非字母数字 JS 代码是如何工作的吗?

javascript - 当我尝试在 Canvas 中创建新图像时,为什么不触发图像加载?

javascript - 如何在 IE9 上的定期 AJAX 请求期间避免内存泄漏

css - IE11 中的 Lit 元素,自定义元素外部的 css 样式影响内部样式

html - IE6 sub 中的菜单列表不下降