前台 <img id="imgHeadurl" runat="server" alt="" style="width:84px; height:86px" 
                        src="" />
                <select 
                        id="select1" name="D1" onchange="change()" runat="server">
                        <option>===请选择===</option>
                        <option value="01.gif">头像1</option>
                        <option value="02.gif">头像2</option>
                        <option value="03.gif">头像3</option>
                        <option value="04.gif">头像4</option>
                        <option value="05.gif">头像5</option>
                        <option value="06.gif">头像6</option>
                  </select>
             
  function change() {
            var pic = document.getElementById('select1').value;
                document.getElementById('imgHeadurl').src = "/index/images/BBS/head_images/"+pic;
            }后台 string img=imgHeadurl.Src.toString()//这里的img永远是空,这是为什么? 我想得到图片信息插入数据看

解决方案 »

  1.   

    document.getElementById('imgHeadurl').src = "/index/images/BBS/head_images/"+pic;
    赋上去的个路径对吗?前面没..吗?
      

  2.   

    当然是单击事件里 protected void Button1_Click(object sender, EventArgs e)
            {
        
                if (imgHeadurl.Src == "" || imgHeadurl.Src == null)//用户没有选择论坛头像
                {
                                           
       }
                else
                {
                                   
      }
    }
      

  3.   

    后台执行 string img=imgHeadurl.Src.toString()的时候
    触发了一次回调,把你的JS赋值给清空了。
      

  4.   

    放在Page_Load外面就可以了,放在里面只是第一次加载的时候赋值,但是你点击的时候页面刷新了啊
      

  5.   

    那咋办? 我这个东西肯定不能卸载Page_Load里面
      

  6.   

    你试试把<select>和<img>换成服务器控件,然后在<dropdownlist>控件的selected事件里写
    this.imgHeadurl.imageURL="/index/images/BBS/head_images/"+this.dropdownlist1.selectedvalue;大概就这么个意思  VS正在修复,属性不一定正确。