阻止IE用户输入到文件上传输入 [英] Stop IE users typing into the file upload input
问题描述
我的测试人员发现,如果你直到该文本被删除输入自由文本到一个文件上传输入然后所有按钮都在页面上工作(所以页面不能提交)。
My testers have discovered that if you type free text into a file upload input then none of the buttons on the page work until that text is removed (so the page cannot be submitted).
我能够(后面没有code)与以下ASPX code复制这样的:
I am able to replicate this with the following ASPX code (with no code behind):
<%@ Page Language="C#" AutoEventWireup="true" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<body>
<form id="form1" runat="server">
<div>
<asp:FileUpload ID="fuTest" runat="server" />
<asp:Button ID="btnSubmit" runat="server" Text="Submit" />
</div>
</form>
</body>
</html>
(请注意,我没有任何的约束处理页面;尽管如此,页面提交时仅当没有文本输入到上传文本框中点击提交按钮)
(Note that I haven't bound any handlers to the page; despite this, the page is submitted when the submit button is clicked only if no text is entered into the upload text box)
有什么办法prevent用户键入自由文本到一个文件上传控件?看来,这仅是在IE中可能的 - 火狐和Chrome原生prevent文本被输入到上传输入字段
Is there any way to prevent users from typing free text into a file upload control? It seems that this is only possible in IE - Firefox and Chrome natively prevent text from being entered into upload input fields.
我见过的解决方案,这在其他地方躲藏建议输入和一个标签/按钮组合取代它,但是这似乎像它可能导致更多的问题和跨浏览器的不一致工作。
I've seen solutions elsewhere which suggest hiding input and replacing it with a label / button combo, but this seems like it might cause more problems and work inconsistently across browsers.
有什么想法?
推荐答案
根据@耶的建议下,我才得以prevent输入到文件上传的未经处理对上传的关键preSS
事件。使用jQuery:
As per @Jer's suggestion, I was able to prevent input into the file upload without breaking any of the other functionality by handling keypress
events on the upload. Using jQuery:
$(document).ready() {
$('input:file').keypress(function() {
return false;
});
}
这篇关于阻止IE用户输入到文件上传输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!