JQuery PreventDefault and IE8 clarification

前端 未结 1 427
礼貌的吻别
礼貌的吻别 2021-01-13 13:58

I have been trying to understand why sometimes IE8 doesn\'t like PreventDefault and why sometimes it seems to be OK (no errors). From what I have read, including here at SO

相关标签:
1条回答
  • 2021-01-13 14:50

    Yes, your understanding sounds correct. Also, if you're using a "DOM0" event handler (e.g. someElement.onclick = function(e) { ... }), there is a simpler way to prevent the browser default behaviour that works in all browsers that support events: return false.

    var someElement = document.getElementById("someElementId");
    someElement.onclick = function(e) {
        // Do some stuff
        return false;
    };
    

    However, in this case, the event is not passed to the event handler in IE <= 8 and you have to get it from window.event instead.

    0 讨论(0)
提交回复
热议问题