控制图片上传大小

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>控制图片上传大小</title>
</head>
<body>
<script language="JavaScript">
var img;
function test(){
if(img)img.removeNode(true);
img=document.createElement('img');
img.style.display='none';
img.attachEvent('onreadystatechange',function() {if(img.readyState=='complete')alert(img.fileSize>102400?'图片尺寸必须小于 1024':'OK');});
img.attachEvent('onerror',function(){alert('不能读取此文件')});
document.body.appendChild(img);
img.src=file.value;
}
</script>
<input name="file" type='file'><input type="button" value="Test" onClick="test()">
</body>
</html>

你可能感兴趣的:(html,XHTML,function,File,input,button)