javascript
function filefujianChange(target) {
var fileSize = 0;
var bro=$.browser;
var binfo="";
if(bro.msie){
var isIE = true;
}
if (isIE && !target.files) {
var filePath = target.value;
var fileSystem = new ActiveXObject("Scripting.FileSystemObject");
var file = fileSystem.GetFile (filePath);
fileSize = file.Size;
} else {
fileSize = target.files[0].size;
}
var size = fileSize / 1024;
//这里限制大小
if(size>2000){
alert("附件不能大于2M");
target.value="";
return
}
var name=target.value;
var fileName = name.substring(name.lastIndexOf(".")+1).toLowerCase();
//这里限制类型
if(fileName !="pdf" && fileName !="ppt"){
alert("请选择PPT或PDF格式文档!");
target.value="";
return
}
}
html
<input type="file" onchange="filefujianChange(this);" />