获取所有select mutiple的值--javascript
functionCreate(SourceSelect,TargetSelect){
varIsCreate=true;
vartheIndex =SourceSelect.selectedIndex;
vartheLength=SourceSelect.length;
if(theIndex==-1)//如果源Select为空的话,则退出过程
returnfalse;
while(IsCreate) //添加到目的Select循环
{
theValue=SourceSelect.options.text; //得到所选择的文本
TargetSelect.options.add(newOption(theValue)); //目的Select增加一个文本
theIndex=theIndex+1; //如果是选择多列的话,对下一个进行处理
if(theIndex==theLength)//theLength如果是4的话,则theIndex应该是3,
{ //如果两者想等的话,则源Select多了一个值,
IsCreate=false; //所以需要退出循环
break;
}
if(SourceSelect.options.selected==false)//如果没有被选择的话,则退出循环
{
IsCreate=false;
}
}
while(IsCreate==false) //删除源select循环
{
SecIndex =SourceSelect.selectedIndex;//动态得到被选择的索引
theLength=SourceSelect.length; //动态得到Select的长度
SourceSelect.remove(SecIndex); //删除指定索引的元素
if(theLength==1) //表示最后一个元素已删除,
returnfalse; //源select空了,退出循环
if(theLength==SecIndex+1) //表示多选的已全部删掉,退出循环
returnfalse;
if(SourceSelect.options.selected==false)
{
IsCreate=true;
}
}
}
页:
[1]