日期:2014-05-16  浏览次数:20637 次

html5 上传实用小例子
js得到上传文件大小和类型和名字
$('#i_submit').click( function() {
? ? //check whether browser fully supports all File API
? ? if (window.File && window.FileReader && window.FileList && window.Blob)
? ? {
? ? ? ? //get the file size and file type from file input field
? ? ? ? var fsize = $('#i_file')[0].files[0].size;
? ? ? ? var ftype = $('#i_file')[0].files[0].type;
? ? ? ? var fname = $('#i_file')[0].files[0].name;
? ? ? ?
? ? ? ? if(fsize>1048576) //do something if file size more than 1 mb (1048576)
? ? ? ? {
? ? ? ? ? ? alert("Type :"+ ftype +" | "+ fsize +" bites\n(File: "+fname+") Too big!");
? ? ? ? }else{
? ? ? ? ? ? alert("Type :"+ ftype +" | "+ fsize +" bites\n(File :"+fname+") You are good to go!");
? ? ? ? }
? ? }else{
? ? ? ? alert("Please upgrade your browser, because your current browser lacks some new features we need!"