event.preventDefault() function not working in IE

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

Following is my JavaScript (mootools) code:

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


        
11条回答
  •  北恋
    北恋 (楼主)
    2020-11-22 02:59

    preventDefault is a widespread standard; using an adhoc every time you want to be compliant with old IE versions is cumbersome, better to use a polyfill:

    if (typeof Event.prototype.preventDefault === 'undefined') {
        Event.prototype.preventDefault = function (e, callback) {
            this.returnValue = false;
        };
    }
    

    This will modify the prototype of the Event and add this function, a great feature of javascript/DOM in general. Now you can use e.preventDefault with no problem.

提交回复
热议问题