直接在绑定事件后添加return false 或
this.blur();window.event.returnValue = false;
html
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> <script src="meishu.js" type="text/javascript"></script> </head> <body> <ul id="list"> <li> <a href="img/04.png" title="hahhah">第一张</a> </li> </ul> <img id="placeholder" src="img/06.png" alt=""> <p id="description">内容</p> </body> </html>
js
window.onload=function(){ function show(whichpic){ var source=whichpic.getAttribute("href"); var placeholder=document.getElementById("placeholder"); placeholder.setAttribute("src",source); var text=whichpic.getAttribute("title"); var description=document.getElementById("description"); description.firstChild.nodeValue=text; } var list=document.getElementById("list"); var links=list.getElementsByTagName("a"); for(var i=0;i<links.length;i++){ links[i].onclick=function(){ show(this); return false; // this.blur(); // window.event.returnValue = false; } } };