<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>DOM编程艺术图片库</title> </head> <body> <h1>Snapshots</h1> <ul> <li><a href="images/5.jpg" onclick="showPic(this); return false;">china map</a></li> <li><a href="images/2.jpg" onclick="showPic(this); return false;">words</a></li> <li><a href="images/3.jpg" onclick="showPic(this); return false;">html</a></li> <li><a href="images/4.jpg" onclick="showPic(this); return false;">friends</a></li> </ul> <img id="placeholder" src="images/1.jpg" alt="my image"> <script src="js/showPic.js"></script> </body> </html>
function showPic(whichpic) { var source = whichpic.getAttribute("href"); var placeholder = document.getElementById('placeholder'); placeholder.setAttribute("src",source); }
效果能实现,就是这个函数传参有点不太明白,望有人能解答的详细的.
清风流光
慕粉1440489053
西兰花伟大炮