[JavaScript] js实现列表可左右移动调整 可排序 →→→→→进入此内容的聊天室

来自 , 2019-03-29, 写在 JavaScript, 查看 111 次.
URL http://www.code666.cn/view/8f53295a
  1.  
  2. <script language="JavaScript">
  3. function copyToList(from,to) //from表示:包含可选择项目的select对象名字 to表示:列出可选择项目的select对象名字 //你可以根据你的具体情况修改
  4. {
  5.   fromList = eval('document.forms[0].' + from);
  6.   toList = eval('document.forms[0].' + to);
  7.   if (toList.options.length > 0 && toList.options[0].value == 'temp')
  8.   {
  9.     toList.options.length = 0;
  10.   }
  11.   var sel = false;
  12.   for (i=0;i<fromList.options.length;i++)
  13.   {
  14.     var current = fromList.options[i];
  15.     if (current.selected)
  16.     {
  17.       sel = true;
  18.       if (current.value == 'temp')
  19.       {
  20.         alert ('你不能选择这个项目!');
  21.         return;
  22.       }
  23.       txt = current.text;
  24.       val = current.value;
  25.       toList.options[toList.length] = new Option(txt,val);
  26.       fromList.options[i] = null;
  27.       i--;
  28.     }
  29.   }
  30.   if (!sel) alert ('你还没有选择任何项目');
  31. }
  32. function allSelect() //这是当用户按下提交按钮时,对列出选择的select对象执行全选工作,让递交至的后台程序能取得相关数据
  33. {
  34.   List = document.forms[0].chosen;
  35.   if (List.length && List.options[0].value == 'temp') return;
  36.   for (i=0;i<List.length;i++)
  37.   {
  38.      List.options[i].selected = true;
  39.   }
  40. }
  41.  
  42. </script>
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55. <table border="0"> <form onSubmit="allSelect()">
  56.               <tr>
  57.                 <td>
  58.                   <select name="possible" size="4"
  59. MULTIPLE width=200 style="width: 200px">
  60.                     <option value="1">中国广州
  61.                     <option value="2">中国上海
  62.                     <option value="3">中国北京
  63.                     <option value="4">中国武汉
  64.                     <option value="5">中国站长
  65.                   </select>
  66.                 </td>
  67.                   <td><a href="javascript:copyToList('possible','chosen')">添加至右方-->
  68.  
  69.                    
  70.  
  71.                     </a><a href="javascript:copyToList('chosen','possible')"><--添加至左方</a></td>
  72.                 <td>
  73.                   <select name="chosen" size="4"
  74. MULTIPLE width=200 style="width: 200px;">
  75.                     <option value="temp">从左边选择你的地区  
  76.                   </select>
  77.                 </td>
  78.               </tr>  </form>
  79.             </table>
  80.            
  81.        

回复 "js实现列表可左右移动调整 可排序"

这儿你可以回复上面这条便签

captcha