This doesn't seem to work neither in IE or Moz. MSDN says: There is no functionality implemented for this property unless defined by the author. http://msdn.microsoft.com/library/de...ies/accept.aspAny suggestions? Here is my ASPX: <%@ Page language="c#" Codebehind="Default.aspx.cs" AutoEventWireup="false" Inherits="Upload.FileFilters._Default" %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" > 我从网上找一些资料 <html> <head> <title>Default</title> </head> <body> <form id="Form1" method="post" runat="server"> <input type="file" id="file1" accept="video/mpeg"> </form> </body> </html> 还有就是设置 filefilter 不过还没有实现。
用正则表达式
不匹配的不通过,提示
匹配的就可以提交
function check(){
var filepath=path.value
filepath=filepath.substring(filepath.lastIndexOf('.')+1,filepath.length)
if(filepath != 'jpg' && filepath != 'gif')
alert("只能上传JPG或GIF格式的图片")
}
</script>
<input type=file name=path onpropertychange="check()"> (只能上传JPG或GIF格式的图片)
http://msdn.microsoft.com/library/de...ies/accept.aspAny suggestions? Here is my ASPX:
<%@ Page language="c#" Codebehind="Default.aspx.cs" AutoEventWireup="false" Inherits="Upload.FileFilters._Default" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
我从网上找一些资料
<html>
<head>
<title>Default</title>
</head>
<body>
<form id="Form1" method="post" runat="server">
<input type="file" id="file1" accept="video/mpeg">
</form>
</body>
</html>
还有就是设置 filefilter
不过还没有实现。
定义和用法accept 属性只能与 <input type="file"> 配合使用。它规定能够通过文件上传进行提交的文件类型。提示:请避免使用该属性。应该在服务器端验证文件上传。
实例在文件上传中使用 accept 属性,本例中的输入字段可以接受 GIF 和 JPEG 两种图像:<form>
<input type="file" name="pic" id="pic" accept="image/gif, image/jpeg" />
</form>如果不限制图像的格式,可以写为:accept="image/*"。
在firefox上及ie上都试了,并不行呀.
另外 一些朋友 提出的检查file元素的value, 这种方法可以但不够完美. 我想在弹出的浏览文件的窗口中就限定用户选择的文件类型.
弹出的浏览文件的窗口中就限定用户选择的文件类型??
你是调用的file,肯定是不行的
除非你自己写弹出框了
要判断可以通过javascript来验证文件的后缀名。
客户端做一次验证,上传到服务器的时候也做一次验证,double check.