IE 10中的event.preventDefault

编程入门 行业动态 更新时间:2024-10-26 22:27:14
本文介绍了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

本文发布于:2023-08-02 16:33:30,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1279330.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:event   preventDefault

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!