fileupload 上传图片之前预览

这个功能很好实现,代码如下:

<%@ Page Language="C#" CodeFile="Default7.aspx.cs" Inherits="Default7" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>无标题页</title>
      <script type="text/javascript">
        function showPreview() {
            var fileName = document.getElementById('<%=FupImg.ClientID%>').value;
            if (fileName != "") {
                document.getElementById('<%=imgPreview.ClientID%>').src = fileName;
            }
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
     <div>
        <img id="imgPreview" runat="server" width="230" height="80" src="7.gif" alt="" style=" 70px; border:1px solid red" />&nbsp;&nbsp;&nbsp;&nbsp;
        <asp:FileUpload ID="FupImg" runat="server" Width="300" onchange="showPreview()" />
  
    </div>
    </form>
</body>
</html>

但是只能在IE6上使用,其他的需要设置一下才可以

如果还是不行,就把站点加到可信任站点中,如图

然后再相应的改一下代码就ok了

多思考,多创新,才是正道!
原文地址:https://www.cnblogs.com/shuang121/p/1970367.html