注册 登录
编程论坛 JavaScript论坛

我的程序阻止默认程序失败了 大神帮我看看哪里出错了

晴天Aspiring 发布于 2016-03-07 18:44, 2610 次点击
window.onload=function(){
    preparegallery();
    showpic();
}
function showpic(whichpic){
    if (!document.getElementById("placeh")) return false;
    var source = whichpic.getAttribute("href");
    var placeh = document.getElementById("placeh");
    if (placeh.nodeName != "IMG") return false;
    placeh.setAttribute("src", source);
    if (document.getElementById("description"))
    {
        var text = whichpic.getAttribute("title") ?  whichpic.getAttribute("title"):"";
        var description = document.getElementById("description");
        if(description.firstChild.nodeType == 3)
        {
            description.firstChild.nodeValue = text;
        }
    }
    return true;
}

function preparegallery(){
    if(!document.getElementsByTagName) return falae;
    if(!document.getElementById) return false;
    if(!document.getElementById("imagegallery")) return false;
    var gallery=document.getElementById("imagegallery");
    var links=gallery.getElementsByTagName("a");
    for(var i=0;i<links.length;i++){
        links[i].onclick=function(){
           return !showpic(this);
        }
    }
}
阻止点击链接的默认事件没有成功 哪里错了
2 回复
#2
冰镇柠檬汁儿2016-03-07 22:00
没看出来你在哪里写了阻止的代码,你代码里的links的onclick只是添加了功能
#3
冰镇柠檬汁儿2016-03-07 22:04
百度一下阻止方法,这是window.evevt(IE或谷歌里)或参数event(火狐)的功能。
1