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" οnchange="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.完成了上传文件,并获取返回值信息。