高分请教!Select框复制问题

KevinAAA 2003-08-22 11:10:07
有2个select框SourceSelect和TargetSelect
问题:将SourseObject中的一项或多项复制到TargetObject,SourseObject中的项存在依附关系,如1000,1100,1110,1111。1000为根节点,如何实现当用户选择1111时,如果目标select中不存在1000,1100,1110,则将这些值同时拷贝到目标select中。复制时用到如下函数:
/*
*多选下拉列表动态增加函数:Create(SourceSelect,TargetSelect);
*参数:SourseObject:表示要动态添加的源Select;
*参数:TargetObject:表示要动态接受的目的Select;
*例:Create(document.all.SourSelect,document.all.TarSelect);
*/
function Create(SourceSelect,TargetSelect)
{
var IsCreate = true;
var theText = "";
var theIndex = SourceSelect.selectedIndex;
var theLength = SourceSelect.length ;
if (theIndex == -1 ) //如果源Select为空的话,则退出过程
return false;
while (IsCreate) //添加到目的Select循环
{
theText = SourceSelect.options[theIndex].text;
theValue = SourceSelect.options[theIndex].value;
for (i = 0 ;i < TargetSelect.length ; i++)
{
HaveIt = true;
if (TargetSelect.options[i].text == theText)
{
alert(theText+":目标select中已存在此项!");
HaveIt = false;
break;
}
else
{
HaveIt = true;
}
}
if (HaveIt)//如果目标select不存在该项,则增加
TargetSelect.options.add(new Option(theText,theValue));
document.all.func_added.options.add(new Option(theText,theValue));

theIndex = theIndex + 1; //如果是选择多列的话,对下一个进行处理
if (theIndex == theLength)
{ //如果两者想等的话,则源Select多了一个值,
IsCreate = false; //所以需要退出循环
break;
}
if (SourceSelect.options[theIndex].selected == false)//如果没有被选择的话,则退出循环
{
IsCreate = false;
}
}
}
...全文
91 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
jsidiot 2003-08-26
  • 打赏
  • 举报
回复
我不太清楚你说的是什么意思?
我的理解是把
document.all.func_added.options.add(new Option(theText,theValue));
注释掉就了
KevinAAA 2003-08-26
  • 打赏
  • 举报
回复
高手哪里去了
KevinAAA 2003-08-22
  • 打赏
  • 举报
回复
没有人会吗???

87,907

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧