定义和用法
getElementById() 方法可返回对拥有指定 ID 的第一个对象的引用。
语法
document.getElementById(id)
说明
HTML DOM 定义了多种查找元素的方法,除了 getElementById() 之外,还有 getElementsByName() 和 getElementsByTagName()。
不过,如果您需要查找文档中的一个特定的元素,最有效的方法是 getElementById()。
在操作文档的一个特定的元素时,最好给该元素一个 id 属性,为它指定一个(在文档中)唯一的名称,然后就可以用该 ID 查找想要的元素。
例子
This is a header
Click on the header to alert its value
document.getElementById()是js对于页面动态的处理,配合PHP使用最佳,通常用AJAX后台网络处理.
你写的有一些拼写错误
- 公告1
- 公告2
- 公告3