1.getElementById 
作用:一般页面里ID是唯一的,用于准备定为一个元素 
语法: document.getElementById(id) 
参数:id :必选项为字符串(String) 
返回值:对象; 返回相同id对象中的第一个,按在页面中出现的次序,如果无符合条件的对象,则返回 null 

代码

  1. example:document.getElementById("id1").value;  

 

2.getElementsByName 
作用:按元素的名称查找,返回一个同名元素的数组 
语法: document.getElementsByName(name) 
参数:name :必选项为字符串(String) 
返回值:数组对象; 如果无符合条件的对象,则返回空数组,按在页面中出现的次序 

代码

  1. example:document.getElementsByName("name1")[0].value;   

  2. document.getElementsByName("name1")[1].value;  

 

3.getElementsByTagName 
作用:按HTML标签名查询,返回一个相同标签元素的数组 
语法: object.getElementsByTagName(tagname) object可以是document或event.srcElement.parentElement等 
参数:tagname:必选项为字符串(String),根据HTML标签检索。 
返回值:数组对象; 如果无符合条件的对象,则返回空数组,按在页面中出现的次序 

代码

  1. example:document.getElementsByTagName("p")[0].childNodes[0].nodeValue;   

  2. document.getElementsByTagName("p")[1].childNodes[0].nodeValue