怎样检测上传文件的大小? 对于IE就用FileSystemObject,对于mozilla,netscape以及Mozilla based browser,惭愧....... 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 有安全提示的.<HTML><HEAD> <SCRIPT> function getFileSize (fileName) { if (document.all) { window.oldOnError = window.onerror; window.onerror = function (err) { if (err.indexOf('utomation') != -1) { alert('没有访问文件的权限'); return true; } else return false; }; var fso = new ActiveXObject('Scripting.FileSystemObject'); var file = fso.GetFile(fileName); window.onerror = window.oldOnError; return file.Size; }} </SCRIPT> </HEAD> <BODY> <FORM NAME="formName"><INPUT TYPE="file" NAME="fileName"><BR> <INPUT TYPE="button" VALUE="查看文件字节大小" ONCLICK="alert(getFileSize(this.form.fileName.value)+'字节')"><BR> </FORM></BODY> </HTML> <SCRIPT language=javascript>function index_image_valid(){ var img=new Image(); img.src=document.pho_up.pho_index.value; imagewidth=img.width; imageheigth=img.height; fsize=img.fileSize/1024; fsize=fsize.toFixed(1); document.pho_up.cmd.disabled=true; if(img.readyState!="complete") window.setTimeout("index_image_valid()",10); else {alert ("宽:"+imagewidth+"\n高:"+imageheigth+"\n大小:"+fsize+" KB"); document.pho_up.cmd.disabled=false}}</script></head><form name="pho_up" method="post" enctype="multipart/form-data"><input type="file" name="pho_index" size="20"><input type=button name="cmd" value="测试图片大小" onclick="index_image_valid();"> </form> 我用wanghr100(灰豆宝宝.net) 的方法试验,运行时提示错误:错误:Automation服务器不能创建对象请各位赐教如何解决。多谢!!! history.go(-1)后button失效 关于return 有效数字不大于8位 的正则表达式该怎么写啊 如何得到 window.open 新页面中的数据 用addEventListener给一组元素添加事件问题 自已写了个鼠标提示,加了onmouseout怎么不管用请高人帮助一下感谢 请教一个小问题 JQuery中怎么设置class呢? 关于在网页中控制flash的问题//在现等待 如何实现让表格中的的某一条线变粗? 判断文件大小 静儿有一个很急的问题需要大侠来帮忙9813117
<SCRIPT> function getFileSize (fileName) { if (document.all) {
window.oldOnError = window.onerror;
window.onerror = function (err) {
if (err.indexOf('utomation') != -1) {
alert('没有访问文件的权限');
return true;
}
else
return false;
};
var fso = new ActiveXObject('Scripting.FileSystemObject');
var file = fso.GetFile(fileName);
window.onerror = window.oldOnError;
return file.Size; }}
</SCRIPT>
</HEAD>
<BODY>
<FORM NAME="formName"><INPUT TYPE="file" NAME="fileName"><BR>
<INPUT TYPE="button" VALUE="查看文件字节大小" ONCLICK="alert(getFileSize(this.form.fileName.value)+'字节')"><BR>
</FORM></BODY>
</HTML>
function index_image_valid(){
var img=new Image();
img.src=document.pho_up.pho_index.value;
imagewidth=img.width;
imageheigth=img.height;
fsize=img.fileSize/1024;
fsize=fsize.toFixed(1);
document.pho_up.cmd.disabled=true;
if(img.readyState!="complete")
window.setTimeout("index_image_valid()",10);
else
{alert ("宽:"+imagewidth+"\n高:"+imageheigth+"\n大小:"+fsize+" KB");
document.pho_up.cmd.disabled=false}
}
</script>
</head>
<form name="pho_up" method="post" enctype="multipart/form-data">
<input type="file" name="pho_index" size="20">
<input type=button name="cmd" value="测试图片大小" onclick="index_image_valid();">
</form>
多谢!!!