列表框操作函数集合

1/*列表框互相操作函数集*/
2
3//描述:添加不重复列表框元素
4functionselAdd(srcList,dstList)
5{
6varselectedIndex=newArray();
7varcount=0;
8
9for(i=0;i<srcList.options.length;i++){
10
11if(srcList.options[i].selected){
12
13selectedIndex[count]=i;
14count++;
15
16}
17}
18
19for(j=0;j<selectedIndex.length;j++){
20
21k=selectedIndex[j];
22
23if(chkDup(srcList.options[k].value,dstList)==false){
24&,nbsp;dstList.options.length++;
25varlen=dstList.options.length-1;
26dstList.options[len].value=srcList.options[k].value;
27dstList.options[len].text=srcList.options[k].text;
28}
29
30}
31
32}
33
34//描述:删除列表框元素
35functionselDel(list)
36{
37varlen=list.options.length;
38varidx=0;
39
40while(idx<len){
41
42if(list.options[idx].selected){
43list.options.remove(idx);
44len=list.options.length;
45}
46else{
47idx++;
48}
49}
50}
51
52//描述:检测列表框元素重复
53functionchkDup(item,list)
54{
55for(i=0;i<list.options.length;i++){
56//alert(item+"-"+list.options[i].value);
57if(item==list.options[i].value){
58returntrue;
59}
60}
61returnfalse;
62}
63
64//描述:选择列表框的全部成员
65functionselSel(list,item)
66{
67item.value="";
68for(i=0;i<list.options.length;i++){
69list.options[i].selected=true;
70item.value+=list.options[i].value+"";
71}
72
73}
74
75functionselSelSingle(list,value)
76{
77for(i=0;i<list.options.length;i++){
78if(list.options[i].value==value){
79list.options[i].selected=true;
80break;
81}
82}
83
84}
85//描述:根据数组初始化列表框
86functionselList(item,arr)
87{
88
89varcurIndex,insIndex,val,text;
90vararrItem=newArray();
91
92if(item){
93
94item.length=0;
95curIndex=0;
96
97for(i=0;i<arr.length;i++){
98
99item.length++;
100insIndex=item.length-1;
101
102if(arr[i]){
103arrItem=arr[i].split(",");
104text=arrItem[1];
105val=arrItem[0];
106item.options[insIndex].text=text;
107item.options[insIndex].value=val;
108}
109}
110
111}
112}
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值