好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

上传文件验证格式与大小_html/css_WEB-ITnose

$(document).ready(function(){ $("#form01").change( 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; }else{$("#name01").text(ext)} var file_size = 0; if ( $.browser.msie) { var img=new Image(); img.src=filepath; while(true){ if(img.fileSize > 0){ if(img.fileSize>3*1024*1024){ alert("图片不大于100MB。"); }else{ var num03 = img.fileSize/1024; num04 = num03.toFixed(2) $(".size02").text(num04+"KB"); } break; } } } else { file_size = this.files[0].size; console.log(file_size/1024/1024 + " MB"); var size = file_size / 1024; if(size > 10240){ alert("上传的文件大小不能超过10M!"); }else{ var num01 = file_size/1024; num02 = num01.toFixed(2) $("#size01").text(num02 + " KB"); } } return true; }); }); 无标题文档

查看更多关于上传文件验证格式与大小_html/css_WEB-ITnose的详细内容...

  阅读:46次