getElementById()
Function: Find the element object with the specified id in the web page.
Syntax: var obj = document.getElementById(id)
Parameters: id refers to the value of the id attribute marked in the web page.
Return value: Returns an element object.
Example: var imgObj = document.getElementById(“img01”)
getElementsByTagName(tagName)
<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>php.cn</title> <script type="text/javascript"> window.onload = function(){ //获取id=ulTag的网页对象 var ulObj = document.getElementById("question"); //查找<ul>下的所有的<li>标记 var arrObj = ulObj.getElementsByTagName("li"); //给所有的<li>标记增加CSS效果 for(var i=0;i<arrObj.length;i++) { //给每个<li>标记加style属性 arrObj[i].style = "color:blue;font-size:24px;"; } } </script> </head> <body > <ul id="question"> <li>mac 中系统自带的apache 误删了怎么恢复</li> <li>CURL POST数据量过大,接收不到服务端的信息</li> <li>用了构造函数为什么这个还是2?</li> <li>cookies登录原理</li> </ul> </html>Next Section