<style type="text/css">
#preview_div
{
/* 该对象用于在IE下显示预览图片 */
filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale);
}
</style>
<script type="text/javascript">
function setImg(fup) {
var temp = fup.value.toLowerCase();
temp = temp.substr(temp.length - 4);
if (temp != ".jpg") {
alert("格式错误");
return false;
}
var ua = navigator.userAgent.toLowerCase();
var preview_div = document.getElementById("preview_div");
var preview_img = document.getElementById("preview_img");
var ver = ua.substr(ua.indexOf("msie") + 5, 1);
if (ver > 6) {
preview_div.filters.item('DXImageTransform.Microsoft.AlphaImageLoader').src = fup.value;
preview_img.style.display = 'none';
}
else {
preview_img.src = fup.value;
}
}
</script>
//省略的表单元素,以下是关键代码
<div id="preview_div" class="size" style="float:left;">
<img id="preview_img" alt="图书封面" height="120" src="../../Images/default.jpg" class="size" />
</div>
<div style="float:left;margin-left:5px; padding-top:98px">
<asp:FileUpload ID="FileUpload1" runat="server" οnchange="setImg(this)" />
</div>