简体   繁体   中英

Blur event function in IE11 and IE10

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.

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

Script Code:

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

ASP.NET MVC HTML code:

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

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?

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

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.

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 needs to be set as the ID attribute of the textbox:

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

In addition:

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

References

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM