<div class="htmlarea"> <textarea id="runcode85236"> <script language="javascript"> var oForm = new Object(); var oImage = new Image(); oImage.attachEvent('onload',getSize); oImage.attachEvent('onerror',doWithError); function checkImage(obj){ oForm = obj; oImage.src = oForm.oFile.value; } function getSize(){ var oImgSize = Math.floor(oImage.fileSize/1024); if(oImgSize>200){ window.alert('不允许上传大于200KB的图片!'); oForm.reset(); } } function doWithError(){ window.alert('出现错误:请重新选择图片上传!'); oForm.reset(); } </script> <form name="data_form" method="post" enctype="multipart/form-data"> <input type="file" name="oFile" onpropertychange="javascript:checkImage(document.data_form);"> </form> </textarea><br><input onclick="runEx('runcode85236')" type="button" value="运行代码"> <input onclick="doCopy('runcode85236')" type="button" value="复制代码"> <input onclick="doSave(runcode85236)" type="button" value="保存代码">[Ctrl+A 全选 注:<a href="http://www.jb51.net/article/23421.htm" title="查看具体详情" target="_blank">如需引入外部Js需刷新才能执行</a>]</div> <br>测试过程,可以通过选择非图片与图片大小超过200K的图片测试。