这是显示图片的页面,用js替换不同来源的占位符。当我单击链接时,我不希望它转到另一个页面<a>
,所以我正在使用onclick="return false"
. 但它不起作用。我找不到问题。
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>my first gallery</title>
<script type="text/javascript" src="scripts/showPic.js"></script>
</head>
<body>
<h1>Snapshot</h1>
<a href="images/6.jpg" onclick="return false; ">Click me</a>
<ul>
<li>
<a href="images/1.jpg" onclick="showPic(this);
return false;" title="first picture" >my favorite </a>
</li>
<li>
**<a href="images/2.jpg" onclick="showPic(this); return false;" title="second picture">second my favorite</a>**
</li>
</ul>
<ol>
<li>
<a href="images/3.jpg" onclick="showPic(this); return false;" title="third picture" >third my favorite </a>
</li>
<li>
<a href="images/4.jpg" onclick="showPic(this); return false;" title="forth picture" >forth my favorite </a>
</li>
</ol>
<!--this the place to show pictures-->
<img id="placeholder" src="images/5.jpg" alt="place holder imga" />
</body>
</html>
JS:
function showPic(whichPic){
var source = whichPic.getAttribute("href");
var placeholder = document.getElementById("placeholder");
placeHolder.setAttribute("scr", source);
}