<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> </head> <body> <p id="foo"></p> <div name="foo"></div> <ul> <li class="demo">111</li> <li>222</li> <li class="demo">333</li> </ul> <div class="demo"></div> <script> var oDiv = document.getElementsByName("foo"); //console.log(oDiv instanceof Object T , Array F); oDiv[0].style.color = "blue"; // ie9以后才支持 var eles = document.getElementsByClassName("demo"); console.log(eles.length);//3 // querySelector querySelectorAll H5高版本浏览器常用选择器 var p1 = document.querySelector("#foo"); console.log(p1); var eles2 = document.querySelectorAll(".demo"); console.log(eles2); </script> </body> </html>
03JavaScript程序设计修炼之道-2019-06-20_20-31-49
原文:https://www.cnblogs.com/HiJackykun/p/11093730.html