日期:2014-05-16  浏览次数:20412 次

javascript新手求助:没有添加onclick事件,却能点击链接成功跳转。请问是正常现象吗?
//html中没有onclick事件
<a href="images/fireworks.jpg" title="A fireworks display">
   Fireworks</a>
    </li>
     <li>
         <a href="images/coffee.jpg" title="A cup of black coffee display">  
   Coffee</a>
    </li>
     <li>
         <a href="images/rose.jpg" title="A red,red rose display">
   Rose</a>
    </li>
     <li>
         <a href="images/bigben.jpg" title="The famous clock display">
   Big Ben</a>

//js文件中也没有onclick事件
/***
ShowPic()函数:该函数的作用是让“占位符”显示自己查看的那张照片
*/
function showPic(whichpic) {
if(!document.getElementById("placeholder")) return true; //如果“placeholder”元素不存在,则执行默认的链接跳转动作
  var source=whichpic .getAttribute( "href");
  var placeholder = document.getElementById("placeholder");
  if(placeholder.nodeName!="IMG") return true; //如果placeholder元素不是图片,则网页跳转。nodeName属性总是返回一个大写字母。
  placeholder.setAttribute("src",source);
  var text = whichpic.getAttribute("title") ? 
  whichpic.getAttribute("title") : "";//如果whichPic的title属性不为空就给他赋值,否则将title致空。
  var description = document.getElementById("description");
  description.firstChild .nodeValue = text;
  return false;
}

但是链接可以正常跳转,求走过路过的大神,给小女子留个声,这正常否?

------解决方案--------------------
超连接 不用onclick事件就能点击,它会跳到转href路劲上,你的路径是一个图片地址,浏览器可以识别所以就能显示了。
------解决方案--------------------
html中有超链接又有地址,当然可以跳转了,你也可是先把脚本注释掉再试试,应该也是可以跳转的