function Add(ObjSource,ObjTarget){
var str;
for(var i=ObjSource.length-1;i>=0;i--){
if(ObjSource.options[i].selected){
ObjTarget.add(new Option(ObjSource.options[i].text,ObjSource.options[i].value,true));
ObjSource.options.removeChild(ObjSource.options[i]);
//document.getElementById("cod").value = ObjSource.options[i].text+",";
str += ObjSource.options[i].text+",";
}
}
document.getElementById("cod").value = str; }我str的取值这样不对吗?

解决方案 »

  1.   

    你都removeChild了,还用这个options[i]来取啊?
      

  2.   

    后台asp.net(c#)
    怎么取值呀
      

  3.   

    如zhaoxiaoyang(梅雪香@深圳)所说,你的算法有问题,removeChild要放在循环的最后
      

  4.   

    <select id="a" size="3" multiple="multiple"><!--多选的时候,mutiple属性是必须的,否则只有最后一个selected选择-->
    <option value="1">a</option>
    <option value="2" selected>b</option>
    <option value="3" selected>c</option>
    </select>
    <select id="b" size="3">
    </select>
    <input type="text" id="cod">
    <script language="JavaScript">
    <!--
    function Add(ObjSource,ObjTarget){
    var str="";
    for(var i=ObjSource.length-1;i>=0;i--)
    {
    if(ObjSource.options[i].selected)
    {
    ObjTarget.add(new Option(ObjSource.options[i].text,ObjSource.options[i].value));
    str += ObjSource.options[i].text+",";
    ObjSource.options.remove(i);
    }
    }
    document.getElementById("cod").value = str;
    }
    //测试
    window.onload=function()
    {
    var a=document.getElementById('a');
    var b=document.getElementById('b');
    Add(a,b);
    }
    //-->
    </script>
      

  5.   

    解决了
    把str的赋值放到前边就解决了
    不过,还得想还有没有别的什么好办法
    不用隐含控件、、、