Why is the onclick function return false not triggered in JavaScript?
滿天的星座
滿天的星座 2017-05-19 10:39:07
0
2
633

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>   
滿天的星座
滿天的星座

reply all(2)
迷茫

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>

大家讲道理

Getting the id is document.getElementById('')

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template