亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

javascript 讀取圖片文件的大小

 更新時(shí)間:2009年06月25日 15:42:08   作者:  
今天弄了一個(gè)附件圖片上傳的,為了寫一個(gè)檢測(cè),很麻煩,后來(lái),發(fā)現(xiàn)一個(gè)比較巧妙的方法
如下:
復(fù)制代碼 代碼如下:

function checkAttachment(){
alert("here");
var attachmentArray = document.getElementsByTagName("input");
var attachmentSizeArray = document.getElementsByName("fileMaxSize");
var index = 0;
for (var i = 0; i < attachmentArray.length; i++){
var attachment = attachmentArray[i];
if (attachment.type=="file"){
if (!isPhoto(attachment.value)){
alert("上傳的附件必須是相片.");
attachment.focus();
return false;
}
if (getFileSize(attachment) > 1024 * attachmentSizeArray[index].value){
alert("上傳的附件不能大于" + attachmentSizeArray[index].value + "k.");
attachment.focus();
return false;
}
index++;
}
}
return true;
}

function getFileSize(fileObject){
var image=new Image();
image.dynsrc=fileObject.value;
return image.fileSize;
}

第一個(gè)方法是獲取頁(yè)面的所有file控件和對(duì)應(yīng)file文件大小的限定,
重點(diǎn)是第二個(gè)方法,很巧妙的用一個(gè)image來(lái)解決,(*^__^*) 嘻嘻……

相關(guān)文章

最新評(píng)論