document 和 document.all 分别什么时候用

2016-02-19 12:51 6 1 收藏

有了下面这个document 和 document.all 分别什么时候用教程,不懂document 和 document.all 分别什么时候用的也能装懂了,赶紧get起来装逼一下吧!

【 tulaoshi.com - Web开发 】

body
div id="aa"123456/div
input type="button" value="这里用 document 就出错" onclick="alert(document.aa.innerText);" /
br /
input type="button" value="这里用 document.all 就不出错" onclick="alert(document.all.aa.innerText);" /
/body 运行以上代码.

(本文来源于图老师网站,更多请访问https://www.tulaoshi.com/webkaifa/)

如果与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来引用

(本文来源于图老师网站,更多请访问https://www.tulaoshi.com/webkaifa/)

all是一个集合,包含所有html对像的集合,写一个程式,可以存取到所有的对像。像这样:
script language="javascript"
var obj="";
for(i=0;idocument.all.length;i++)
obj+=document.all[i].tagName+";";
alert(obj);
/script
注意要把程式放到/html之后哦。

来源:https://www.tulaoshi.com/n/20160219/1602167.html

延伸阅读
标签: Web开发
Demonstration script that opens and prints and existing Microsoft Word document.  代码如下: Set objWord = CreateObject("Word.Application") Set objDoc = objWord.Documents.Open("c:\scripts\inventory.doc") objDoc.PrintOut() objWord....
标签: Web开发
Demonstration script that retrieves service information from a  computer and then displays that information in tabular format in Microsoft Word. 代码如下: Set objWord = CreateObject("Word.Application") objWo...
标签: Web开发
firefox 的 event.currentTarget 和 ie 的 document.activeElement 这两个完全含义不一致的对象却被捆绑在一起做成了浏览器兼容代码。 大家在的时候 都会发现 document.activeElement || event.currentTarget 的用法。 其实这样的用法是错误的,因为这两个属性的意义都不一样。   Identifies the current target for the event,...
标签: Web开发
Demonstration script that retrieves service data from a computer and  then displays that data in a formatted table in Microsoft Word.  代码如下: Set objWord = CreateObject("Word.Application") objW...
你了解面霜吗?你知道什么使用面霜最好吗?4个因素决定你是否要使用面霜。 一:你的年龄 当你的肌肤处于某个年龄段时,它所需要的营养成分,普通的水质乳液已经无法满足其需求,只有面霜才可以。大多数面霜的价格相对比较昂贵,所谓科技含量往往是其昂贵的理由。 二:你的工作环境 你是不是经常处于很干燥而且到处都...

经验教程

379

收藏

73
微博分享 QQ分享 QQ空间 手机页面 收藏网站 回到头部