1 dom中查找html
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>lizi</title> <style> .ptest { font-size:40px; } </style> </head> <body> <p id="lizi"></p> <p ></p> <p class="ptest"></p> 姓:<input type="text" name="username"> 名:<input type="text" name="username"> <script> var element=document.getElementById("lizi"); element.innerHTML="<span style='color: red'>this is lizi test</span>"; document.getElementsByName("username")[0].value = "li"; document.getElementsByTagName("p")[1].innerText = "this is second p"; document.getElementsByTagName("p")[1].style.color = "blue"; document.getElementsByClassName("ptest")[0].innerHTML="<span>this is p class test</span>"; </script> </body> </html>