According to the javascript dom programming art about the part of the web page that displays pictures, the code is typed out. There is a section that requires input onclick="showPic(this);return false;" to prevent the web page from popping up new links to view pictures. But when I finally ran it, a new link still popped up. The specific code is as follows:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<title>My Gallery</title>
</head>
<body>
<h1>snapshots</h1>
<ul>
<li>
<a href="images/do or die.jpg" onclick="showPic(this);return false;" title="do or die">DO</a>
</li>
<li>
<a href="images/hand.jpg" onclick="showPic(this);return false;" title="hand">HAND</a>
</li>
<li>
<a href="images/phrase.jpg" onclick="showPic(this);return false;" title="phrase">Phrase</a>
</li>
</ul>
<img id="placeholder" src="images/dog.jpg" alt="My Gallery"/>
<script>
function showPic(whichpic)
{var source=whichpic.getAttribute ("href");
var placeholder=document.getElenmentById ("placeholder");
placeholder.setAttribute("src",source);}
</script>
</body>
</html>
迷茫2017-05-19 10:41:07
First of all, the words you get the id are spelled wrong, and secondly, the href pointing problem of the a tag conflicts with the click event
<!DOCTYPE html>
<html lang="en">
<head>
< meta charset="utf-8"/>
<title>My Gallery</title>
</head>
<body >
<h1>snapshots</h1>
<ul>
<li>
<a href="javascript:;" date-href="zhc1.jpg" onclick="showPic(this);return false;" title="do or die">DO</a>
</li>
<li>
<a href="javascript:;" date-href="zhc2.jpg" onclick="showPic(this);return false;" title="hand">HAND</a>
</li>
<li>
<a href="javascript:;" date-href="zhc3.jpg" onclick="showPic(this);return false;" title="phrase">Phrase</a>
</li>
</ul>
<img id="placeholder" src="zixun_video_pic.jpg" alt="My Gallery"/>
<script>
function showPic(whichpic){
var source=whichpic.getAttribute ("date-href");
var placeholder=document.getElementById ("placeholder");
placeholder.setAttribute("src",source);
}
</script>
</body>
</html>