js的用setAttribute圖片切換
阿新 • • 發佈:2018-11-01
<ul>
<li>
<a href="images/1.jpg" title="asd1" onclick="showPic(this);return false;">Firrworks</a>
</li>
<li>
<a href="images/2.jpg" title="asd2" onclick="showPic(this);return false;">Firrworks1</a>
</li>
<li>
<a href="images/3.jpg" title="asd3" onclick="showPic(this);return false;">Firrworks2</a>
</li>
<li>
<a href="images/4.jpg" title="asd4" onclick="showPic(this);return false;">Firrworks3</a>
</li>
</ul>
<li>
<a href="images/1.jpg" title="asd1" onclick="showPic(this);return false;">Firrworks</a>
</li>
<li>
<a href="images/2.jpg" title="asd2" onclick="showPic(this);return false;">Firrworks1</a>
</li>
<li>
<a href="images/3.jpg" title="asd3" onclick="showPic(this);return false;">Firrworks2</a>
</li>
<li>
<a href="images/4.jpg" title="asd4" onclick="showPic(this);return false;">Firrworks3</a>
</li>
</ul>
<img id="placeholder" src="images/5.jpg" alt="our hello" >
function showPic(Whichpic){
var source=Whichpic.getAttribute("href");
var placeholder=document.getElementById('placeholder');
placeholder.setAttribute("src",source);
}