需求是做两个select ,设定成为multiple;
两个框分别放不同人,可以互相添加;
双击左面框的人,就会自动添加到右边,在左边这里删除这个人;
这些现在都实现了;
由于每边的人太多了。所以做了一个ajax效果的搜索,根据搜索条件,填充select;
缩小范围;
但是用ajax添加select以后,一但把所有的项目都移走的话,这边的select也就自动被删除了。这是为什么?
如果不用ajax搜索,把所有项目都移动到另一边。select只是空了,并没有被删除;
下面是两个select移动的代码;
//====================================================================
function SelItem(sel_source, sel_dest)
{
//首先拷贝所有项目到目标:
var sel_source_len = sel_source.length;
var i = 0;
for (var j=0; j <sel_source_len; j++)
{
if(sel_source.options[i].selected)
{
var SelectedText = sel_source.options[i].text;
var SelectedValue = sel_source.options[i].value;
for (var y=0;y <sel_dest.length;y++)
{
if(sel_dest.options[y].text== " ")
{
sel_dest.options.remove(y);
}
}
sel_dest.options.add(new Option(SelectedText,SelectedValue));
sel_source.options.remove(i);
}
else
{
i++;
}
}
}
function MoveAllItems(sel_source, sel_dest)
{
//首先拷贝所有项目到目标:
var sel_source_len = sel_source.length;
for (var j=0; j <sel_dest.length; j++)
{
if(sel_dest.options[j].text== " ")
{
sel_dest.options.remove(j);
}
}
for (var j=0; j <sel_source_len; j++)
{
var SelectedText = sel_source.options[j].text;
var SelectedValue = sel_source.options[j].value;
sel_dest.options.add(new Option(SelectedText,SelectedValue));
}
while ((k=sel_source.length-1)> =0)
{
sel_source.options.remove(k);
}
}
//================================================================
下面是异步数据以后,添加到指定select的方法;
//================================================================
function chkSearchResult(re)
{
var xmlDoc = re.responseXML;
var select;
var success = getElementText( "success ",xmlDoc,0);
if(success== "false ")
{
alert( "没有查询到相关结果 ");
return ;
}
switch($F( "sSide "))
{