getElementById与getElementsByName 与getElementsByTagName总结
2009-11-20 21:30
375 查看
getElementById与getElementsByName 与getElementsByTagName总结
1.getElementById (它是获取ID)
作用:一般页面里ID是唯一的,用于准备定为一个元素
语法: document.getElementById(id)
参数:id :必选项为字符串(String)
返回值:对象; 返回相同id对象中的第一个,按在页面中出现的次序,如果无符合条件的对象,则返回 null
代码
example:document.getElementById("id1").value;
2.getElementsByName (它是获取name)
作用:按元素的名称查找,返回一个同名元素的数组
语法: document.getElementsByName(name)
参数:name :必选项为字符串(String)
返回值:数组对象; 如果无符合条件的对象,则返回空数组,按在页面中出现的次序
代码
example:document.getElementsByName("name1")[0].value;
document.getElementsByName("name1")[1].value;
3.getElementsByTagName (它是获取HTML标签(元素))
作用:按HTML标签名查询,返回一个相同标签元素的数组
语法: object.getElementsByTagName(tagname) object可以是document或event.srcElement.parentElement等
参数:tagname:必选项为字符串(String),根据HTML标签检索。
返回值:数组对象; 如果无符合条件的对象,则返回空数组,按在页面中出现的次序
代码
example:document.getElementsByTagName("p")[0].childNodes[0].nodeValue;
document.getElementsByTagName("p")[1].childNodes[0].nodeValue
1.getElementById (它是获取ID)
作用:一般页面里ID是唯一的,用于准备定为一个元素
语法: document.getElementById(id)
参数:id :必选项为字符串(String)
返回值:对象; 返回相同id对象中的第一个,按在页面中出现的次序,如果无符合条件的对象,则返回 null
代码
example:document.getElementById("id1").value;
2.getElementsByName (它是获取name)
作用:按元素的名称查找,返回一个同名元素的数组
语法: document.getElementsByName(name)
参数:name :必选项为字符串(String)
返回值:数组对象; 如果无符合条件的对象,则返回空数组,按在页面中出现的次序
代码
example:document.getElementsByName("name1")[0].value;
document.getElementsByName("name1")[1].value;
3.getElementsByTagName (它是获取HTML标签(元素))
作用:按HTML标签名查询,返回一个相同标签元素的数组
语法: object.getElementsByTagName(tagname) object可以是document或event.srcElement.parentElement等
参数:tagname:必选项为字符串(String),根据HTML标签检索。
返回值:数组对象; 如果无符合条件的对象,则返回空数组,按在页面中出现的次序
代码
example:document.getElementsByTagName("p")[0].childNodes[0].nodeValue;
document.getElementsByTagName("p")[1].childNodes[0].nodeValue
相关文章推荐
- getElementByID getElementsByName getElementsByTagName的区别和总结
- getElementById与getElementsByName 与getElementsByTagName的区别总结
- getElementByID getElementsByName getElementsByTagName的区别和总结 +js+Mxl+xmlhttp
- getElementByID getElementsByName getElementsByTagName的区别和总结
- getElementByID getElementsByName getElementsByTagName的区别和总结
- getElementByID getElementsByName getElementsByTagName的区别和总结
- getElementByID getElementsByName getElementsByTagName的区别和总结
- getelementbyid, getelementsbyname, getelementsbytagname 的区别和总结
- getElementById、 getElementsByName 和getElementsByTagName的用法
- document,document.all,getElementById,getElementsByName,getElementsByTagName
- DOM的getElementById()、getElementsByName()、getElementsByTagName()方法
- getElementById() getElementsByTagName() getElementsByClassName() querySlector() querySlectorAll()区别
- getElementById(), getElementsByName(), and getElementsByTagName()使用与区别
- document.all与getElementById、getElementsByName、getElementsByTagName用法区别-getElementsByName
- getElementByID,getElementsByName,getElementsByTagName的区别
- JavaScript中getElementById和 getelementsByName和getElementsByTagName的简单应用
- (转)Javascript如何正确使用getElementById,getElementsByName() and getElementsByTagName()
- document.getElementsByName()与 document.getElementById()、document.getElementsByTagName()的区别
- Javascript中getElementById与getElementsByName与getElementsByTagName的不同
- getElementByID() getElementsByName() getElementsByTagName()的区别