document.all和document.forms [0]之间的区别 [英] difference between document.all and document.forms[0]

查看:123
本文介绍了document.all和document.forms [0]之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以解释

document.all


document.forms [0] 请?

谢谢

推荐答案

document.all 为您提供对类似于数组的对象的引用,该对象包含Internet Explorer (IE)中文档的所有元素。 Document.forms [0] 为您提供指向文档中第一个表单元素的指针,所有浏览器中的

document.all gives you a reference to an array-like object containing all elements of the document in Internet Explorer (IE). Document.forms[0] gives you a pointer to the first form element in the document, in all browsers

2则完全不同。如果你的表单有一个name属性,比如'myform',那么在IE中,那个表单可以用 document.all.myform

The 2 are quite different then. If your form had a name attribute, say 'myform', then in IE that form could be referenced with document.all.myform

document.all 。你仍然可以使用它,即使在IE9中它仍然可用。通常它用于测试浏览器是否为IE:

document.all is deprecated from IE version 5 and up. You can still use it though, even in IE9 it's still available. Often it's used to test if the browser is IE:

if (document.all) {
  //o no, it's IE again! We have to do it another way!
}

形式引用表格document.forms [ 0] 被认为是不好的做法。有关详细信息,请访问此处

Referencing forms in the form of document.forms[0] is considered bad practice. More on that can be found here

注意:由于这个答案是第一次写的,IE11已经被引入,它不再支持document.all 有关详细信息,请参阅IE11中的兼容性更改

NOTE: Since this answer was first written IE11 has been introduced which dropped support for document.all See Compatibility changes in IE11 for more information

这篇关于document.all和document.forms [0]之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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