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

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)
迷茫

首先是你的id获取单词都拼错了,其次是a标签href指向问题和点击事件冲突




My Gallery



snapshots



My Gallery


Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!