document属性

 1.document和document.all

 

参见http://www.w3school.com.cn/htmldom/dom_obj_document.asp

 

 如果与a,form对象,image对象,applet,input对象相对应的html标记中设定了name性质,它的值将被用作document对象的属性名,用来引用相应的对象,其他的对象则不可以。例如

 <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);" />


 另外,input等如果作为form的子元素,则直接用inputName或者document.inputName来引用此对象就是错误的,必须使用formName.inputName引用,否则就可以使用inputName来引用.例如

 <html> <head> <title></title> </head> <body> <input name="test1" type="text" value="转换之前"> <form name="from1"> <input name="test2" type="text" value="转换之后"> <input name="button" type="button" value="try" onclick=try1();alert("..."+from1.test2.value);> </form> <mce:script language </body><!-- ="javascript"> function try1(){ alert(test1.value); alert(from1.test2.value); } // --></mce:script> </html>

2.document.all的用法

<div id="docid" name="docname"></div>,你可以通过这个DIV的ID,NAME或INDEX属性访问这个DIV: document.all["docid"] document.all["docname"] document.all.item("docid") document.all.item("docname") document.all[7] document.all.tags("div")则返回文档中所有DIV数组,本例中只有一个DIV,所以用document.all.tags("div")[0]就可以访问了

 

3.documen的方法

getElementById()

getElementsByName()

getElementsByTagName()

 

你可能感兴趣的:(JavaScript,function,input,div,button,applet)