<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<form method='post' name='UserSelectForm' id='UserSelectForm' onSubmit="return false">
 <table width='100%' cellspacing='1' class='configtable'>
  <tr class="usertrbg1">
   <td align='right' nowrap class="p10">部门选择:</td>
   <td width='90%' class="pr10"><select id='AllDept' name='AllDept' style="display:inline;width:100%;" onChange="vbscript:DeptSwitch">
     <option value='All' selected>所有部门</option>
     <option value='1'>外交部</option>
     <option value='2'>管理部</option>
     <option value='3'>商务部</option>
     <option value='4'>工商部</option>
     <option value='5'>公安部</option>
    </select></td>
  </tr>
  <tr>
   <td colspan=2 class="p10"><table width='100%' cellspacing='1' class='configtable'>
     <tr align='center'>
      <td><select multiple id='Preselecter' name='Preselecter' style="display:inline;width:100%;" size='9' rows='9' ondblclick="vbscript:SelectOne">
        <option value=1>用户1[商务部]</option>
        <option value=2>用户2[商务部]</option>
        <option value=3>用户3[管理部]</option>
        <option value=4>用户4[公安部]</option>
        <option value=5>用户5[公安部]</option>
        <option value=6>用户6[外交部]</option>
        <option value=7>用户7[外交部]</option>
       </select></td>
      <td valign='center' width='40'></td>
      <td class=row><select multiple id='Selecteder' name='Selecteder' style="display:inline;width:100%;" size=9 rows=9 ondblclick="vbscript:BackOne">
       </select></td>
     </tr>
    </table></td>
  </tr>
 </table>
</form>
</BODY>
</html>
<script language=vbscript>
<!--
 dim ary()
 redim ary(2,0)
 redim ary(2,7)
ary(0,0)=""
ary(1,0)=""
ary(2,0)=""
ary(0,1)="1" //用户ID
ary(1,1)="用户1[商务部]" //用户名称
ary(2,1)="3" //部门ID
ary(0,2)="2" //用户ID
ary(1,2)="用户2[商务部]" //用户名称
ary(2,2)="3" //部门ID
ary(0,3)="3" //用户ID
ary(1,3)="用户3[管理部]" //用户名称
ary(2,3)="2" //部门ID
ary(0,4)="4" //用户ID
ary(1,4)="用户4[公安部]" //用户名称
ary(2,4)="5" //部门ID
ary(0,5)="5" //用户ID
ary(1,5)="用户5[公安部]" //用户名称
ary(2,5)="5" //部门ID
ary(0,6)="6" //用户ID
ary(1,6)="用户6[外交部]" //用户名称
ary(2,6)="1" //部门ID
ary(0,7)="7" //用户ID
ary(1,7)="用户7[外交部]" //用户名称
ary(2,7)="1" //部门ID sub DeptSwitch
  dim i,e,j,ba
  for i= 0 to UserSelectForm.Preselecter.options.length-1
   UserSelectForm.Preselecter.options.remove 0
  next
  for i=1 to ubound(ary,2)
   if UserSelectForm.AllDept.value=ary(2,i) or UserSelectForm.AllDept.value="All" then
    ba=0
    for j=0 to UserSelectForm.Selecteder.length-1
     if ary(0,i)=UserSelectForm.Selecteder.item(j).value then
      ba=1
      exit for
     end if
    next
    if ba=0 then
     Set e = Document.createElement("OPTION")
     e.value=ary(0,i)
     e.text=ary(1,i)
     UserSelectForm.Preselecter.options.add e
    end if
   end if
  next
 end sub
//-->
</script>

解决方案 »

  1.   


    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    </head>
    <body>
    <form method='post' name='UserSelectForm' id='UserSelectForm' onSubmit="return false">
     <table width='100%' cellspacing='1' class='configtable'>
      <tr class="usertrbg1">
       <td align='right' nowrap class="p10">部门选择:</td>
       <td width='90%' class="pr10"><select id='AllDept' name='AllDept' style="display:inline;width:100%;" onChange="DeptSwitch()">
         <option value='All' selected>所有部门</option>
         <option value='1'>外交部</option>
         <option value='2'>管理部</option>
         <option value='3'>商务部</option>
         <option value='4'>工商部</option>
         <option value='5'>公安部</option>
        </select></td>
      </tr>
      <tr>
       <td colspan=2 class="p10"><table width='100%' cellspacing='1' class='configtable'>
         <tr align='center'>
          <td><select multiple id='Preselecter' name='Preselecter' style="display:inline;width:100%;" size='9' rows='9' ondblclick="SelectOne()">
            <option value=1>用户1[商务部]</option>
            <option value=2>用户2[商务部]</option>
            <option value=3>用户3[管理部]</option>
            <option value=4>用户4[公安部]</option>
            <option value=5>用户5[公安部]</option>
            <option value=6>用户6[外交部]</option>
            <option value=7>用户7[外交部]</option>
           </select></td>
          <td valign='center' width='40'></td>
          <td class=row><select multiple id='Selecteder' name='Selecteder' style="display:inline;width:100%;" size=9 rows=9 ondblclick="BackOne()">
           </select></td>
         </tr>
        </table></td>
      </tr>
     </table>
    </form>
    </BODY>
    </html>
    <script language=javascript>
    <!--
    var ary = [];
    for(var i=0;i<8;i++) ary[i] = [];
    ary[0][0]=""
    ary[0][1]=""
    ary[0][2]=""
    ary[1][0]="1" //用户ID
    ary[1][1]="用户1[商务部]" //用户名称
    ary[1][2]="3" //部门ID
    ary[2][0]="2" //用户ID
    ary[2][1]="用户2[商务部]" //用户名称
    ary[2][2]="3" //部门ID
    ary[3][0]="3" //用户ID
    ary[3][1]="用户3[管理部]" //用户名称
    ary[3][2]="2" //部门ID
    ary[4][0]="4" //用户ID
    ary[4][1]="用户4[公安部]" //用户名称
    ary[4][2]="5" //部门ID
    ary[5][0]="5" //用户ID
    ary[5][1]="用户5[公安部]" //用户名称
    ary[5][2]="5" //部门ID
    ary[6][0]="6" //用户ID
    ary[6][1]="用户6[外交部]" //用户名称
    ary[6][2]="1" //部门ID
    ary[7][0]="7" //用户ID
    ary[7][1]="用户7[外交部]" //用户名称
    ary[7][2]="1" //部门IDfunction DeptSwitch(){
      var i,e,j,ba
      document.UserSelectForm.Preselecter.options.length = 0;
      for(var i=1;i<ary.length;i++){
        if(document.UserSelectForm.AllDept.value == ary[i][2] || document.UserSelectForm.AllDept.value=="All"){
          ba = 0
          for(j=0;j<document.UserSelectForm.Selecteder.options.length;j++){
            if(ary[i][0]==document.UserSelectForm.Selecteder.options[j].value){
              ba=1
              break
            }
          }
          if (ba==0){
            document.UserSelectForm.Preselecter.options.add(new Option(ary[i][1],ary[i][0]));
          }
        }
      }
    }
    function SelectOne(){}
    function BackOne(){}//-->
    </script>
      

  2.   

    请问这里的i<8是什么?
    这个数组是不定的。从数据库中读取出来的,写成8是不是不对啊?
      

  3.   

    redim ary(2,7) <---这里不是写了7吗, 8就是7+1, 要么就写i<=7
    客户端代码和数据库没什么关系,后台生成代码的时候,相应位置填写记录总数就可以了.
      

  4.   

    不好意思,在chrome下还是不能用啊,只能在IE中运行。不知道哪里有问题?
    从vbscript改javascript就是为了让chrome兼容
      

  5.   


    知道了  谢谢hookee大侠!
    帮我好几次了