Returning false from click handler doesn't work in Firefox

前端 未结 3 830
星月不相逢
星月不相逢 2020-12-10 04:21

In the example below, return false does not seem to prevent the default action after the link is clicked (because the page scrolls to the top) in Firefox 3.6 or

3条回答
  •  -上瘾入骨i
    2020-12-10 05:13

    You say "preventDefault() helps" but you say it doesn't work? I'm not sure I understand. Have you tried this:

    addEventListener("DOMContentLoaded", function() {
        document.getElementById("link").addEventListener("click", function(e) {
            alert("Clicked!");
            e.preventDefault();
            return false;
        }, false);
        alert("Click handler bound!");
    }, false);
    

提交回复
热议问题