html dom小案例
阿新 • • 發佈:2018-12-26
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title></title> </head> <body> <ul> <li> <a class="pop" href="img/a.jpg" onclick="show()" title="a">a</a> </li> <li> <a class="pop" href="img/b.jpg" title="b">b</a> </li> <li> <a class="pop" href="img/c.png" title="c">c</a> </li> <li> <a class="pop" href="img/d.png" title="d">d</a> </li> <li> <a class="pop" href="img/e.png" title="e">e</a> </li> </ul> <script type="text/javascript"> window.onload = function() { //確保向後相容性 if(!document.getElementsByTagName)) { return false; } var list = document.getElementsByTagName("a"); for(var i = 0; i < list.length; i++) { if(list[i].getAttribute("class") == "pop") { list[i].onclick = function() { window.event.returnValue = false; popUp(this.getAttribute("href")); } } } } function popUp(href) { window.open(href, "newPop", "width=300,height=200"); } </script> </body> </html>