ListBox的操作

   主要实现功能是将ListBox1中的选择项移动到ListBox2中:
  
 1 function  moveOption(e1, e2,type)
 2                  {
 3                    if( type == 'part' )
 4                    {
 5                        for(var i=0;i<e1.options.length;i++)
 6                        {
 7                            if(e1.options[i].selected)
 8                            {
 9                                var e = e1.options[i];
10                                e2.options.add(new Option(e.text, e.value));
11                                e1.remove(i);
12                                i=i-1
13                            }

14                        }

15                    }

16                    
17                    if( type == 'all' )
18                    {
19                        for(var i=0;i<e1.options.length;i++)
20                        {
21                            var e = e1.options[i];
22                            e2.options.add(new Option(e.text, e.value));
23                            e1.remove(i);
24                            i=i-1
25                        }

26                    }

27                    document.all.HiddenprjA.value = getvalue( document.all.lbprjnameA );
28                    document.all.HiddenprjB.value = getvalue( document.all.lbprjnameB );
29                }

30                 
31                  function  getvalue(listContrl) {
32                var allvalue = "";
33                for(var i=0;i<listContrl.options.length;i++){
34                allvalue +=listContrl.options[i].value + ",";
35                }

36                return allvalue;
37                }
   说明:e1,e2分别是ListBox1和ListBox2,type指的是是否全部移动,当然,要保存到数据库中还是需要在后台写一部分代码的。

你可能感兴趣的:(listbox)