1 <!DOCTYPE html> 2 <html> 3 <head lang="en"> 4 <meta charset="UTF-8"> 5 <title></title> 6 <script> 7 window.onload = function () { 8 9 var eleNode = document.getElementsByTagName("img")[0]; 10 11 //属性、赋值获取两种方式 12 //1.元素节点.属性或者元素节点[属性] 13 eleNode.src = "image/jd2.png"; 14 eleNode.aaa = "bbb"; 15 console.log(eleNode.aaa); 16 console.log(eleNode.src); 17 console.log(eleNode.tagName); 18 console.log(eleNode["title"]); 19 console.log(eleNode["className"]); 20 console.log(eleNode["alt"]); 21 22 //2.元素节点.方法(); 23 console.log(eleNode.getAttribute("id")); 24 eleNode.setAttribute("id","你好"); 25 eleNode.setAttribute("ccc","ddd"); 26 27 eleNode.removeAttribute("id"); 28 } 29 </script> 30 </head> 31 <body> 32 <img src="image/jd1.png" class="box" title="图片" alt="京东狗" id="aaa"/> 33 </body> 34 </html>