function aa() {
            var list3 = document.getElementById("<%# ListBox3.ClientID %>");
            var list4 = document.getElementById("<%# ListBox4.ClientID %>");
            var frag = document.createDocumentFragment();
            for(var i =0;i<list3.length;i++)
            {
                var oOption = document.createElement("option");
                oOption.setAttribute("value",list3[i].value);
                oOption.innerHTML=list3[i].value;
                frag.appendChild(oOption);
            }
            list4.appendChild(frag);
            list3.length=0;
        }
为什么缺少对象 function aa() {
            var list3 = document.getElementById("<%= ListBox3.ClientID %>");
            var list4 = document.getElementById("<%= ListBox4.ClientID %>");
            var frag = document.createDocumentFragment();
            for(var i =0;i<list3.length;i++)
            {
                var oOption = document.createElement("option");
                oOption.setAttribute("value",list3[i].value);
                oOption.innerHTML=list3[i].value;
                frag.appendChild(oOption);
            }
            list4.appendChild(frag);
            list3.length=0;
        }
在别的程序上能用 我的就不能用 有错误 要是吧<%=%>改成<%#%>我的就能用了
但是 提示我错误 缺少对象  for(var i =0;i<list3.length;i++)
这句

解决方案 »

  1.   

    <%#%>这个不可以吧,<%#%>是用于数据绑定的,应该用<%=%>
      

  2.   

    你可以 alert(list3)看下是不是 undefined呀,如果是肯定报错啦,说明
    var list3 = document.getElementById("<%# ListBox3.ClientID %>");
     有问题
      

  3.   

    我要是等 <%=%>
    就出现The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>). 
    错误
      

  4.   

    用了 等于null
    那怎么解决????、
      

  5.   

    document.getElementById(" <%# ListBox3.ClientID %>"); 
    没有获取到值。ListBox3.ClientID 看是否有这个元素
      

  6.   

    ListBox3必须存在,而且是public滴
      

  7.   

    先看看你页面内是不是有服务器控件ListBox3
    指定是要用<%=%>
      

  8.   

    我都说了 用<%=%>我有错误就出现The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>). 
      

  9.   

    你用<%# %>肯定是错的,因为这种写法是写在数据绑定控件中的,之所以用<%= %>会出现The Controls collection cannot be modified because the control contains code blocks 这个错误,我觉得可能是因为你的这段代码是写在<head></heda>中的,而且head加了runat="server",所以它会出现这个错误,你把这段js移到</head>和<body>之间试试。
      

  10.   

    1. 肯定是要用<%= %>
    2. 错误信息很明确地说了, 有了这个东西后, 就不能再修改控件集. 你的代码里修改了控件集, 才报的错. 并不是因为<%= 报错. 
      

  11.   

    yuqicook19880808 说的对  这样做就可以了