模糊事件在IE11和IE10中不起作用 [英] Blur event not working in IE11 and IE10

查看:379
本文介绍了模糊事件在IE11和IE10中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的ASP.Net MVC应用程序中有一个文本框,当文本框失去焦点时我需要进行一些验证,因此我使用了模糊事件.

I have a textbox in my ASP.Net MVC application and I need to do some validation when the textbox loses focus, so I have used a blur event.

以下事件在Chrome浏览器中可以正常运行,但在IE11和IE10中不能正常运行.

The below event is working fine in Chrome browser but not working in IE11 and IE10.

脚本代码:

$("#NewFileName").on("blur", function () {
alert('triggered');
});

ASP.NET MVC HTML代码:

ASP.NET MVC HTML code:

<div class ="span6">
                <p>
                    @Html.TextBoxFor(m => m.FileName, new { type = "file" }) 
                </p>
</div>

我尝试使用IE的"focusout"之类的不同事件,但是IE中没有焦点/模糊事件. IE10和11浏览器的正确事件是什么?

I tried with different events like "focusout" for IE, but no focus/blur event are working in IE. What is the correct event for IE10 and 11 browsers?

推荐答案

由于安全限制,文件输入类型在IE中不支持focusblur:

File input types do not support focus and blur in IE due to security restrictions:

Windows Internet Explorer 8表单提交已更改,因此文件上载控件(输入类型=文件)仅将文件路径提交到服务器.以前,完整路径已发送到服务器.同样,对文件上载控件的value属性的编程访问也会从文件名中删除路径信息.

Windows Internet Explorer 8 form submission has been changed so that a file upload control (input type=file) only submits the file path to the server. Previously, the full path was sent to the server. Also, programmatic access to the value property of the file upload control also removes the path information from the file name.

此功能没有解决方法,并且可能无法关闭.提供对文件完整路径的访问(对于Internet和受限制的站点)是一种安全措施.在这些情况下,如果删除完整路径,则会阻止相对不受控制的站点访问可能被利用的信息.

There is no workaround for this feature and it may not be turned off. Providing access to the full path of the file (for Internet and Restricted sites) is a security measure. Stripping out the full path in these instances prevents relatively uncontrolled sites from accessing information that can potentially be exploited.

需要将

NewFileName设置为文本框的ID属性:

NewFileName needs to be set as the ID attribute of the textbox:

@Html.TextBoxFor(m => m.FileName, @id = "NewFileName") 

此外:

在Microsoft Internet Explorer 5和更高版本中,公开模糊方法的元素必须设置TABINDEX属性.

In Microsoft Internet Explorer 5 and greater, elements that expose the blur method must have the TABINDEX attribute set.

参考

Internet Explorer应用程序兼容性:事件1056-文件名限制

Internet Explorer 7和模糊(输入类型=文件)| Matthias Wessendorf的博客

使用onBlur验证输入type = file

为ID属性提供编辑器

这篇关于模糊事件在IE11和IE10中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆