要实现真正的客户端验证可能很难做到,一般客户端都禁止了JS访问FSO
<script language="javascript">
var imgtmp = null;
function aa(){
var file = document.getElementById("FilePath");
alert(file.value);
imgtmp = document.createElement("img");
imgtmp.src = file.value;
imgtmp.attachEvent("onreadystatechange",showfilesize);imgtmp.attachEvent("onerror",alerterr);
document.body.insertAdjacentElement("beforeend",imgtmp);
imgtmp.src=file.value;
}
function showfilesize(){
if(imgtmp.readyState!="complete")
return false;
else
alert("图片大小" + imgtmp.fileSize);
}
function alerterr(){
alert("上传图片类型为:GIF、JPEG/JPG、BMP");
}
</script>
</head>
<body>
<form action="" enctype="multipart/form-data">
上传图片
<input type=file name="FilePath" id="FilePath" size=8 >
<input type="button" name="Submit" value="提交" onClick="aa()">
</form>