JavaScript獲取li的數量 修改其樣式 刪除其中一個li
阿新 • • 發佈:2019-01-08
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Test</title> <script type="text/javascript"> window.onload = function () { var myul = document.getElementById("ulme"); var myli = myul.getElementsByTagName("li"); alert(myli.length); for (var j = 0; j < myli.length; j++) { myli[j].style.border = "1px solid #000"; } var every=document.getElementById("everywhere"); every.parentNode.removeChild(every); } </script> </head> <body> <ul id="ulme"> <li id="everywhere">It can be found everywhere.</li> <li class="test">It's easy to use.</li> <li class="test">It can help you to find what you want,really quickly.</li> </ul> </body> </html>
不知道為什麼直接用documnet.getElementsByTagName("li")就不行。