管理杂谈OA答疑ERP答疑教程搜索

下拉列表左右移动或交换数据代码


下拉框的数据来回交换,记得最早是在人才网站选择职位时候发现的这种功能,本款是模仿的,功能有点不一样,只提供一种思路,希望对你有帮助。

​ 

<title>

    列表数据交换

</title><script language="JavaScript">function copyToList(from,to) { 

  fromList = eval('document.forms[0].' + from); 

  toList = eval('document.forms[0].' + to); 

  if (toList.options.length > 0 && toList.options[0].value == 'temp') 

  { 

    toList.options.length = 0; 

  } 

  var sel = false; 

  for (i=0;i<fromList.options.length;i++) 

  { 

    var current = fromList.options[i]; 

    if (current.selected) 

    { 

      sel = true; 

      if (current.value == 'temp') 

      { 

        alert ('你不能选择这个项目!'); 

        return; 

      } 

      txt = current.text; 

      val = current.value; 

      toList.options[toList.length] = new Option(txt,val); 

      fromList.options[i] = null; 

      i--; 

    } 

  } 

  if (!sel) alert ('你还没有选择任何项目'); 

function allSelect() { 

  List = document.forms[0].chosen; 

  if (List.length && List.options[0].value == 'temp') return; 

  for (i=0;i<List.length;i++) 

  { 

     List.options[i].selected = true; 

  } 


</script>

<table border="0">

    <tbody>

        <tr class="firstRow">

            <td>

                <select name="possible" size="4" multiple="" width="200" style="width: 200px"><option value="1">

                    长沙

                </option>

                <option value="2">

                    天津

                </option>

                <option value="3">

                    南京

                </option>

                <option value="4">

                    武汉

                </option>

                <option value="5">

                    郑州

                </option></select>

            </td>

            <td>

                <a href="javascript:copyToList('possible','chosen')">--><br/> 

                    <br/> 

                    </a><a href="javascript:copyToList('chosen','possible')"><--</a>

            </td>

            <td>

                <select name="chosen" size="4" multiple="" width="200" style="width: 200px;"><option value="temp">

                    选择地区

                </option></select>

            </td>

        </tr>

    </tbody>

</table>


更多精彩文章浏览...
点击右上角图标分享到朋友圈
官方网站:http://www.clicksun.cn
咨询热线:400-186-1886
服务邮箱:service@clicksun.cn