event.preventDefault() function not working in IE

后端 未结 11 2779
栀梦
栀梦 2020-11-22 02:22

Following is my JavaScript (mootools) code:

$(\'orderNowForm\').addEvent(\'submit\', function (event) {
    event.prev         


        
11条回答
  •  滥情空心
    2020-11-22 03:00

    To disable a keyboard key after IE9, use : e.preventDefault();

    To disable a regular keyboard key under IE7/8, use : e.returnValue = false; or return false;

    If you try to disable a keyboard shortcut (with Ctrl, like Ctrl+F) you need to add those lines :

    try {
        e.keyCode = 0;
    }catch (e) {}
    

    Here is a full example for IE7/8 only :

    document.attachEvent("onkeydown", function () {
        var e = window.event;
    
        //Ctrl+F or F3
        if (e.keyCode === 114 || (e.ctrlKey && e.keyCode === 70)) {
            //Prevent for Ctrl+...
            try {
                e.keyCode = 0;
            }catch (e) {}
    
            //prevent default (could also use e.returnValue = false;)
            return false;
        }
    });
    

    Reference : How to disable keyboard shortcuts in IE7 / IE8

提交回复
热议问题