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的取值这样不对吗?
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的取值这样不对吗?
怎么取值呀
<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>
把str的赋值放到前边就解决了
不过,还得想还有没有别的什么好办法
不用隐含控件、、、