我正在阅读http://dev.w3.org/html5/markup/input.file.html,但我只找到了"接受"属性.
我试过这个
<input type="file" name="imagefilename" accept="image/x-png, image/gif, image/jpeg" />
Run Code Online (Sandbox Code Playgroud)
是否可以对文件大小进行客户端验证?
我发现了IE的这种技术
<html>
<head>
<script>
function getSize()
{
var myFSO = new ActiveXObject("Scripting.FileSystemObject");
var filepath = document.upload.file.value;
var thefile = myFSO.getFile(filepath);
var size = thefile.size;
alert(size + " bytes");
}
</script>
</head>
<body>
<form name="upload">
<input type="file" name="file">
<input type="button" value="Size?" onClick="getSize();">
</form>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
是否可以使用html5文件系统api做同样的事情?
UPDATE
我可以这样做(演示):
<!doctype html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js"></script>
</head>
<body>
<form >
<input type=file id=f max-size=32154 >
<input type=submit>
</form> …
Run Code Online (Sandbox Code Playgroud)