<script type="text/javascript">
$(document).ready(function(){
$("#form0").submit(function() {
var filepath=$("input[name='myFile']").val();
var extStart=filepath.lastIndexOf(".");
var ext=filepath.substring(extStart,filepath.length).toUpperCase();
if(ext!=".BMP"&&ext!=".PNG"&&ext!=".GIF"&&ext!=".JPG"&&ext!=".JPEG"){
alert("图片限于bmp,png,gif,jpeg,jpg格式");
return false;
}
var img=new Image();
img.src=filepath;
while(true){
if(img.fileSize>0){
if(img.fileSize>3*1024){
alert("图片不大于300KB。");
return false;
}
break;
}
}
return true;
});
});
</script>
$(document).ready(function(){
$("#form0").submit(function() {
var filepath=$("input[name='myFile']").val();
var extStart=filepath.lastIndexOf(".");
var ext=filepath.substring(extStart,filepath.length).toUpperCase();
if(ext!=".BMP"&&ext!=".PNG"&&ext!=".GIF"&&ext!=".JPG"&&ext!=".JPEG"){
alert("图片限于bmp,png,gif,jpeg,jpg格式");
return false;
}
var img=new Image();
img.src=filepath;
while(true){
if(img.fileSize>0){
if(img.fileSize>3*1024){
alert("图片不大于300KB。");
return false;
}
break;
}
}
return true;
});
});
</script>
本文介绍了一个使用JavaScript实现的图片上传验证脚本,该脚本能够检查上传文件是否为bmp、png、gif、jpeg或jpg格式,并确保其大小不超过300KB。
100

被折叠的 条评论
为什么被折叠?



