<div class="codetitle"> <span><a style="CURSOR: pointer" data="57098" class="copybut" id="copybut57098" onclick="doCopy('code57098')"><u>复制代码</u></a></span> 代码如下:</div> <div class="codebody" id="code57098"> <br><script language="javascript"><br><br> /* 列表框互相操作函数集 */<br><br> //描述: 添加不重复列表框元素<BR> function selAdd( srcList, dstList )<BR> {<BR> var selectedIndex = new Array();<BR> var count = 0;<br><br> for ( i=0; i<srcList.options.length; i++ ){<br><br> if ( srcList.options[i].selected ){<br><br> selectedIndex[count] = i;<BR> count ++;<br><br> }<BR> } <br><br> for ( j=0; j<selectedIndex.length; j++ ){<br><br> k = selectedIndex[j];<br><br> if ( chkDup( srcList.options[k].value, dstList )==false ){<BR> &, nbsp; dstList.options.length++;<BR> var len = dstList.options.length-1;<BR> dstList.options[len].value = srcList.options[k].value;<BR> dstList.options[len].text = srcList.options[k].text;<BR> }<br><br> }<br><br> }<br><br> //描述: 删除列表框元素<BR> function selDel( list )<BR> {<BR> var len = list.options.length;<BR> var idx = 0;<br><br> while ( idx< len ){<br><br> if ( list.options[idx].selected ){<BR> list.options.remove(idx);<BR> len = list.options.length;<BR> }<BR> else{<BR> idx ++;<BR> }<BR> }<BR> }<br><br> //描述: 检测列表框元素重复<BR> function chkDup( item, list )<BR> {<BR> for ( i=0; i<list.options.length; i++ ){<BR> //alert( item + " - " + list.options[i].value );<BR> if ( item == list.options[i].value ){<BR> return true;<BR> }<BR> } <BR> return false;<BR> }<br><br> //描述: 选择列表框的全部成员<BR> function selSel( list, item )<BR> {<BR> item.value = " ";<BR> for ( i=0; i<list.options.length; i++ ){<BR> list.options[i].selected=true;<BR> item.value += list.options[i].value + " ";<BR> }<br><br> }<br><br> function selSelSingle( list, value )<BR> {<BR> for ( i=0; i<list.options.length; i++ ){<BR> if ( list.options[i].value == value ){<BR> list.options[i].selected=true;<BR> break;<BR> }<BR> }<br><br> }<BR> //描述: 根据数组初始化列表框<BR> function selList( item, arr )<BR> {<br><br> var curIndex, insIndex, val, text;<BR> var arrItem = new Array();<br><br> if ( item ){<br><br> item.length = 0;<BR> curIndex = 0;<br><br> for ( i=0; i<arr.length; i++ ){<br><br> item.length ++;<BR> insIndex = item.length - 1;<br><br> if ( arr[i] ){<BR> arrItem = arr[i].split( ", " );<BR> text = arrItem[1];<BR> val = arrItem[0];<BR> item.options[ insIndex ].text = text; <BR> item.options[ insIndex ].value= val;<BR> }<BR> }<br><br> }<BR>} <br><br> </script><br> </div>