1. 程式人生 > >IE8下上傳檔案方式

IE8下上傳檔案方式

1.準備頁面,

加入

<form name="uploadform" id="uploadform" method="post" action="queryCriteriaBD!uploadImageProxy.action" target="file_upload_return" enctype="multipart/form-data">
<div class="top-nav-condition-left-xuanze-imgbox">
<a class="btn_addPic" href="javascript:void(0);" title="支援jpg、jpeg格式,檔案小於5M">
<img class="top-nav-condition-left-xuanze-img" id="top_nav_condition_left_xuanze_img" title="支援jpg、jpeg格式,檔案小於5M" src="../../srtProject/sysc/imgs/SelectImg.png"/>
<div class="top-nav-condition-left-xuanze-img" id="top_nav_condition_left_xuanze_imgDiv" style="display:none;"></div>
<input type="file" tabIndex="3" size="3"  class="filePrew" onchange="chacgeImg(this.value);" id="file" name="file" title="支援jpg、jpeg格式,檔案小於5M">
</a>
</div>
<div class="top-nav-condition-left-xuanze-btnbox" style="display:block;">
<input type="submit" class="frame-btn top-nav-condition-left-xuanze-btn1" value="上傳圖片" id="file_up">
</div> 
</form>

<iframe name="file_upload_return" id="file_upload_return"  style="width:0px;height:0px;border:none;overflow:hidden;"></iframe>

2.在js中加入

//圖片預覽chacgeImg
function chacgeImg(value){
jQuery("#loadgif").css("display","block");
var imgType=value.substring(value.lastIndexOf("."));
if(imgType!=".jpg" && imgType!=".JPG"){
jQuery("#loadgif").css("display","none");
window.alert("圖片只支援(.jpg、.JPG)格式");
}else{
jQuery("#loadgif").css("display","none");
jQuery("#top_nav_condition_left_xuanze_img").css("display","none");
var imgDiv = document.getElementById("top_nav_condition_left_xuanze_imgDiv"); 
        imgDiv.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod = scale)";
         imgDiv.filters("DXImageTransform.Microsoft.AlphaImageLoader").src = value;
jQuery("#top_nav_condition_left_xuanze_imgDiv").css("display","block");

}
}

3.返回iframe的載入成功方法:

jQuery("#file_upload_return").load(function(){
var bodyContent = window.frames["file_upload_return"].document.body.innerHTML;
alert(bodyContent );
});

4.完成了上傳檔案,並獲取返回值資訊。