日期:2014-05-20 浏览次数:21164 次
<script type="text/javascript">
function getFullPath(divImage, upload, width, height){
if(upload.value==""){
return false;
}
var isImage = /\.jpg|\.jpeg|\.gif|\.png|\.bmp$/i;
if (!isImage.test(upload.value)) {
alert("图片格式错误,请重新选择!");
return false;
}
var imgPath; //图片路径
var Browser_Agent = navigator.userAgent;
var Preview = document.getElementById(divImage);
Preview.innerHTML = "";
if (Browser_Agent.indexOf("Firefox") != -1)//判断浏览器的类型
{
//火狐浏览器
imgPath = upload.files[0].getAsDataURL();
Preview.innerHTML = "<img id='imgPreview' src='" + imgPath
+ "' width='" + width + "' height='" + height + "'/>";
} else {
if (navigator.userAgent.indexOf("MSIE 6.0") == -1
&& navigator.userAgent.indexOf("MSIE") > -1) {
upload.select();
var imgSrc = document.selection.createRange().text;
//IE7、8预览方式
Preview.filters.item("DXImageTransform.Microsoft.AlphaImageLoader").src = imgSrc;
Preview.style.width = width;
Preview.style.height = height;
} else {
// IE6预览方式
Preview.innerHTML = "<img id='photo" + "' src='"
+ upload.value + "' style='width:" + width + "px;height:"
+ height + "px;' />";
}
}
}
</script>
<body>
<s:file name="doctorPhoto" id="doctorPhoto"
onchange="getFullPath('Preview',this,150,120);"
cssStyle=" width:166px;" />
<div id="Preview" style="filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale);">
<img id="photo"
src="<%=request.getContextPath()%>/images/1.gif" width="150"
height="120" border="1" />
</div>
</body>