日期:2014-05-17  浏览次数:20392 次

预览图片出现错误
<div style="padding-top:10px;">
  <asp:FileUpload ID="flBigClassPic" onchange="YuLanImg(ctl00_ContentPlaceHolder1_flBigClassPic);" runat="server" /></div>
  <div style="width: 140px; height: 160px; margin-top: 10px; margin-bottom: 10px;">
  <img alt="" src="" width="140" height="160" id="bigclassPic" />
  </div>


下面是js脚本
function YuLanImg(ctl00_ContentPlaceHolder1_flBigClassPic){
  document.getElementById("#bigclassPic").src=ctl00_ContentPlaceHolder1_flBigClassPic.value;
}

------解决方案--------------------
你不能这样做,JS能让你访问本地图片吗?这样太不安全了。
document.getElementById("bigclassPic").src=ctl00_ContentPlaceHolder1_flBigClassPic.value;中#不要
------解决方案--------------------
用 Jquery取Dom 时一般需要id前加上#

直接用则document.getElementById("bigclassPic") 不需要加#

除非你的

<img alt="" src="" width="140" height="160" id="#bigclassPic" />
------解决方案--------------------
怎麼不用專業控件啊

例如:ImageGear 20,Atalasoft DotImage 10f
------解决方案--------------------
而且最好这样定义,否则当页面控件结构稍微有相关改变,会死的很惨

<div style="padding-top:10px;">
<asp:FileUpload ID="flBigClassPic" onchange="YuLanImg('<%= flBigClassPic.ClientID%>');" runat="server" /></div>