event.preventDefault() function not working in IE

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

Following is my JavaScript (mootools) code:

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


        
11条回答
  •  说谎
    说谎 (楼主)
    2020-11-22 02:48

    If you bind the event through mootools' addEvent function your event handler will get a fixed (augmented) event passed as the parameter. It will always contain the preventDefault() method.

    Try out this fiddle to see the difference in event binding. http://jsfiddle.net/pFqrY/8/

    // preventDefault always works
    $("mootoolsbutton").addEvent('click', function(event) {
     alert(typeof(event.preventDefault));
    });
    
    // preventDefault missing in IE
    
    

    For all jQuery users out there you can fix an event when needed. Say that you used HTML onclick=".." and get a IE specific event that lacks preventDefault(), just use this code to get it.

    e = $.event.fix(e);
    

    After that e.preventDefault(); works fine.

提交回复
热议问题