本文介绍了IE 10中的event.preventDefault的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在提交表单,并且在执行其他一些操作(例如显示文件上传的进度条)之前,我想阻止提交操作.我根据SO问题设置了此代码,例如 event.preventDefault()function not在IE中工作.

I am submitting a form and I want to prevent the submit action until I do a few other actions like showing a progress bar for file uploads. I set up this code based on SO questions such as event.preventDefault() function not working in IE.

$(document).ready(function(){
    $("#fileform").submit(function(e){
        if(!e) e = window.event;
        if (e.preventDefault){
            // Firefox, Chrome
            e.preventDefault();
        }else{
            // Internet Explorer
            e.returnValue = false;
        }

        // other code
    }
}

在Firefox和Chrome中一切正常.阻止提交操作,出现进度条,然后在我告诉它时提交表单.但是,在IE 10中,如果执行了if语句的第一个条件,并且该表单似乎正在尝试提交(出现了IE 10的提交气泡).为什么要执行第一个条件?

Everything works fine in Firefox and Chrome; the submit action is prevented, the progress bar appears and then the form is submitted when I tell it to. However, in IE 10, the first condition of the if statement is executed and the form seems to be trying to submit (IE 10's submit bubbles show up). Why is the first condition being executed?

在IE 8和9不支持的情况下,IE 10是否支持preventDefault()?如果是这样,我该如何正确处理以防止在IE 8、9、10中进行表单提交操作,而该操作不会干扰Firefox,Chrome,Safari等...?

Does IE 10 support preventDefault() where IE 8 and 9 didn't? If so, how do I properly handle preventing the form submit action in IE 8, 9, 10 that won't interfere with Firefox, Chrome, Safari, etc...?

推荐答案

只需执行以下操作,jQuery就已经为您完成了跨浏览器的工作.

Just do the below, jQuery has already done the cross browser job for you.

$("#fileform").submit(function(e){
   e.preventDefault();
   // other code
});

这篇关于IE 10中的event.preventDefault的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 13:55