最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
getElementByid ,ByName ByTagName三者区别
时间:2008-04-23 编辑:简简单单 来源:一聚教程网
getElementByid ,getElementsByName getElementsByTagName三者区别
getElementById:
语法: document.getElementById(id)
参数:id :必选项为字符串(String)
返回值:对象; 返回相同id对象中的第一个,如果无符合条件的对象,则返回 null
example:document.getElementById("id1").value;
getElementsByName:
语法: document.getElementsByName(name)
参数:name :必选项为字符串(String)
返回值:数组对象; 如果无符合条件的对象,则返回空数组
example:document.getElementsByName("name1")[0].value;
document.getElementsByName("name1")[1].value;
getElementsByTagName:
语法: object.getElementsByTagName(tagname) object可以是document或event.srcElement.parentElement等
参数:tagname:必选项为字符串(String)
返回值:数组对象; 如果无符合条件的对象,则返回空数组
example:document.getElementsByTagName("p")[0].childNodes[0].nodeValue;
document.getElementsByTagName("p")[1].childNodes[0].nodeValue;
-
上一个: 模仿Google的搜索提示框
-
下一个: 创建表单网页_FrontPage
相关文章
- fckeditor在ie9中不支持$=document.getElementById解决办法 01-05
- dom教程:getElementById() 和 getElementsByTagName() 11-25
- HTML简单购物数量小程序代码展示 10-31
- html canvas实现弹幕功能 10-31
- HTML中空格表示的意义 10-31
- html area标签解读 10-31