<div class="codetitle"> <span><a style="CURSOR: pointer" data="47582" class="copybut" id="copybut47582" onclick="doCopy('code47582')"><u>复制代码</u></a></span> 代码如下:</div> <div class="codebody" id="code47582"> <br>function validateFileSize(id, maxsize) {<br> var btnsave = document.getElementById("Button2");<br> btnsave.disabled = false;<br> var filepath = "";<br> var fileupload = document.getElementById(id);<br> if (fileupload.value.length < 5) { alert('请选择文件!'); return; }<BR> var agent = window.navigator.userAgent;<BR> if (document.all) {<BR> var isIE7 = agent.indexOf('MSIE 7.0') != -1;<BR> var isIE8 = agent.indexOf('MSIE 8.0') != -1;<BR> //IE7和IE8获得文件路径<BR> if (isIE7 || isIE8) {<BR> fileupload.select();<BR> filepath = document.selection.createRange().text;<BR> }<BR> //IE6获得文件路径<BR> else<BR> { filepath = file.value; }<BR> //PageMethods.ValidateFile(filepath, maxsize, ieCallBack);<BR> alert(filepath);<BR> }<BR> if (agent.indexOf("Firefox") >= 1) {<br> alert("FF");<br> alert(getValue());<br> return false;<br> if (fileupload.files) {<br> var size = fileupload.files[0].fileSize;<br> if (size > parseInt(maxsize)) {<br> fileupload.parentNode.innerHTML = '<input type="file" name="' fileupload.name '" id="' fileupload.id '" onchange="disableSave(this);"/> ';<br> alert("文件超过大小!");<br> }<br> else { alert("文件上传成功!"); }<br> }<br> }<br> }<br> </div>