当前位置:编程学习 > C#/ASP.NET >>

求救,图片显示问题

<script language="javascript";>
function checkData()
{
var fileName=document.getElementById("FileUp").value;
if(fileName=="")
return;
//检查文件类型
var exName=fileName.substr(fileName.lastIndexOf(".")+1).toUpperCase()
if(exName=="JPG"||exName=="BMP"||exName=="GIF")
{
    //document.getElementById("myimg").src=fileName;
    document.getElementById("previewImage").innerHTML='<img src=\''+fileName+'\' width=100 height=100 >';
}
else
if(exName=="SWF")
{
document.getElementById("previewImage").innerHTML='<embed src=\''+fileName+'\' width=\'100\' height=\'100\' quality=\'high\' bgcolor=\'#f5f5f5\' ></embed>';
}
else
if(exName=="WMV"||exName=="MPEG"||exName=="ASF"||exName=="AVI")
{
var strcode='<embed src=\''+fileName+'\' border=\'0\' width=\'100\' height=\'100\' quality=\'high\' ';
strcode+=' autoStart=\'1\' playCount=\'0\' enableContextMenu=\'0\' type=\'application/x-mplayer2\'></embed>';
document.getElementById("previewImage").innerHTML=strcode;
}
else
{
alert("请选择正确的图片文件");
document.getElementById("FileUp").value="";
}
}
function checkData2()
{
var fileName=document.getElementById("FileUpSmall").value;
if(fileName=="")
return;
//检查文件类型
var exName=fileName.substr(fileName.lastIndexOf(".")+1).toUpperCase()
if(exName=="JPG"||exName=="BMP"||exName=="GIF")
{
    //document.getElementById("myimg").src=fileName;
    document.getElementById("previewSmallImage").innerHTML='<img src=\''+fileName+'\' width=100 height=100 >';
}
else
if(exName=="SWF")
{
document.getElementById("previewSmallImage").innerHTML='<embed src=\''+fileName+'\' width=\'100\' height=\'100\' quality=\'high\' bgcolor=\'#f5f5f5\' ></embed>';
}
else
if(exName=="WMV"||exName=="MPEG"||exName=="ASF"||exName=="AVI")
{
var strcode='<embed src=\''+fileName+'\' border=\'0\' width=\'100\' height=\'100\' quality=\'high\' ';
strcode+=' autoStart=\'1\' playCount=\'0\' enableContextMenu=\'0\' type=\'application/x-mplayer2\'></embed>';
document.getElementById("previewSmallImage").innerHTML=strcode;
}
else
{
alert("请选择正确的图片文件");
document.getElementById("FileUpSmall").value="";
}
}


</script>
///////////////////////////////////////

商品图片:
                                            </td>
                                            <td height="25" width="*" align="left">
                                                <table border="0" cellpadding="0" cellspacing="0" width="100%" height="100%">
                                                    <tr>
                                                        <td width="400" height="100%" valign="middle">
                                                        
                                                        <input id="FileUp" style="width: 253px; height: 22px" type="file" size="23" name="File1" 
                                                                runat="server"/>

                                                        </td>
                                                        <td>

                                                            <div id="previewImage">
                                                          </div>
                                                        </td>
                                                    </tr>
                                                </table>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td height="25" align="right">
上面是主要代码,怎么点击浏览选择图片后就可以在image框显示图片,不要再点击上传,看不到所得的效果,没有把图片显示出来啊?哪里出了问题?谢谢!
                                                --------------------编程问答-------------------- 说明,input事件在Page_Load里 this.FileUp.Attributes.Add("OnChange", "checkData()"); --------------------编程问答-------------------- 这个简单啊,网上搜一下就得到答案了.
补充:.NET技术 ,  ASP.NET
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,