JS---获取元素的方法
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> </head> <body> <input id="txt1" name="username" class="login"> <script> var o1=document.getElementById("txt1"); var o2=document.getElementsByClassName("login")[0]; var o3=document.getElementsByName("username")[0]; var o4=document.getElementsByTagName("input")[0]; var o5=document.querySelector("#txt1"); var o6=document.querySelectorAll("#txt1")[0]; console.log(o1==o2);//true console.log(o2==o3);//true console.log(o3==o4);//true console.log(o4==o5);//true console.log(o5==o6);//true </script> </body> </html>