<div class="codetitle"> <span><a style="CURSOR: pointer" data="3713" class="copybut" id="copybut3713" onclick="doCopy('code3713')"><u>複製程式碼</u></a></span> 程式碼如下:</div> <div class="codebody" id="code3713"> <br><div id="imgbox"> <br> <img id="imghead" src="img/no_photo.gif" alt="" style="max-width:90%" style="max-width:90%"><br> </div> <br><fileupload id="FileUploadImg" runat="server" onchange="previewImage(this);"> relative;left:-130px;cursor:pointer ;"/><br>var $$ = function(id) {<br> return "string" == typeof id ? document.getElementById(id) : id;<br>};<br>/*<br>/*<br>圖片驗證<br>*/<br>//驗證上傳圖片格式<br>function checkupload(ele) {<br> var obj = $$("FileUploadImg");<br> (/^(.*)(.)(.{1,8})$/)[3]; //這個檔案類型正規很有用:) <br> if (fileContentType == 'gif' || fileContentType = = 'jpeg' || fileContentType == 'png' || fileContentType == 'jpg') {<br> //驗證上傳圖片大小<br> alert ('上傳檔案格式不正確!');<br> return false;<br> }<br> return false;<br>}<br>//驗證上傳圖片尺寸🎜> var maxSize = 100 * 1024;<br> //ie<br> if (window.navigator.userAgent.indexOf("MSIE") >= 1) {<o> try {<br> fso = new ActiveXObject('Scripting.FileSystemObject');<br> .Size);<br> return file.Size } catch (e) {<br> alert("瀏覽器設定停用ActiveX }<br> }<br> //firefox<br> else if (window.navigator.userAgent.indexOf("Firefox") >= 1) {<br> //alert(ele.files[0].fileSize);<br> maxSize;<br> }<br> return false;<br>}<br>//載入預覽圖<br>function previewImage(ele) {<br> . imgDiv = $$("imgbox");<br> imgDiv.innerHTML = "";<br> imgDiv. ";<br> / /ie<br> if (window.navigator.userAgent.indexOf("MSIE") >= 1) {<br> <br> imgDiv.filters("DXImageTransform.Microsoft imgDiv.filters("DXImageTransform.Microsoft else if (window.navigator.userAgent.indexOf("Firefox") >= 1) {<br> imgDiv.innerHTML = "<img style="max-width:90%" 100 "' height='" 125 "' id="aPic" src="%22%20get.s.itemUR(L).%20>%22;<BR>%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%20%7D%20else%20%7B<BR>%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%20imgDiv.innerHTML%20=%20%22<span%20style%C2%A0red;" alt="圖片上傳判斷及預覽腳本的效果實例_javascript技巧" >IE/mgDiv.innerHTML = "<span style>IE/T > } else {<br> $$("FileUploadImg").value = "";<br> $$("imgbox")。 ='' width='100' style="max-width:90%" />";<br> //alert('重設上傳控制');<br> }<br>}<br><br> }<br>}<br><br> }<br>}<br><br><br></span></o></fileupload> </div>