Html:
1 <H1>Snapshots</H1>2 <ul>3 <Li><ahref= "images/1.jpg"onclick= "show (this); return false;"title= "one" >First picture</a></Li>4 <Li><ahref= "images/2.jpg"onclick= "show (this); return false;"title= "both" >Second picture</a></Li>5 <Li><ahref= "images/3.jpg"onclick= "show (this); return false;"title= "three" >The third picture</a></Li>6 <Li><ahref= "images/4.jpg"onclick= "show (this); return false;"title= "four" >Picture Four</a></Li>7 </ul>8 <!--the onclick event function is triggered and returns false so the link is not opened -9 <ahref= "http://www.baidu.com"onclick= "return false">Click Me to Baidu</a>Ten <imgID= "pla"src= "images/6.jpg"/alt= "picture library">
Javascript:
1<script type= "text/javascript" >2 /*3 name This function showpic, and give the function a parameter named Whichpic4 get the position of the PLA and assign it to the variable placeholder5 use the SetAttribute method to refresh the SRC attribute of the placeholder element6 }*/7 functionShow (pic) {8 varSour = pic.getattribute (' href '));9 varplaceholder = document.getElementById (' pla ');TenPlaceholder.setattribute (' src ', sour); one } a</script>
JavaScript learning: Photo Gallery