有了下面这个document 和 document.all 分别什么时候用教程,不懂document 和 document.all 分别什么时候用的也能装懂了,赶紧get起来装逼一下吧!
【 tulaoshi.com - Web开发 】
body  div id="aa"123456/div
div id="aa"123456/div  input type="button" value="这里用 document 就出错" onclick="alert(document.aa.innerText);" /
input type="button" value="这里用 document 就出错" onclick="alert(document.aa.innerText);" /  br /
br /  input type="button" value="这里用 document.all 就不出错" onclick="alert(document.all.aa.innerText);" /
input type="button" value="这里用 document.all 就不出错" onclick="alert(document.all.aa.innerText);" / 
/body 运行以上代码.
如果与a,form对象,image对象,applet对象相对应的html标记中设定了name性质,它的值将被用作document对象的属性名,用来引用相应的对象,其他的对象则不可以。 
另外,input等如果作为form的子元素,则直接用inputName或者document.inputName来引用此对象就是错误的,必须使用formName.inputName引用,否则就可以使用inputName来引用. 
另外应该注意到有很多平时用的元素都没有name. 
如果想引用一个有id的元素,只能用Id或者document.getElementById,document.all.id来引用 
但是象这样的元素,所以象a href="......" name="linkname" id="linkid"....../a这样的 
可以用 
linkid.href; 
linkname.href; 
document.all.linkid.href; 
document.all.linkname.href; 
document.getElementById("linkid").href; 
document.getElementsByName("linkname")[0].href来引用
all是一个集合,包含所有html对像的集合,写一个程式,可以存取到所有的对像。像这样: 
script language="javascript" 
var obj=""; 
for(i=0;idocument.all.length;i++) 
obj+=document.all[i].tagName+";"; 
alert(obj); 
/script 
注意要把程式放到/html之后哦。
来源:http://www.tulaoshi.com/n/20160219/1602167.html
看过《document 和 document.all 分别什么时候用》的人还看了以下文章 更多>>