欢迎光临
我们一直在努力

一段有趣并且实用的程序–利用javascript和dhtml实现两个列表框中内容的移动。(代码见内,把它存为一个…

建站超值云服务器,限时71元/月

<table width=400 align=center border=0>

   <tr>
     <td width=40% align=center>
         列表一
     </td>
     <td width=20% align=center>
         操作
     </td>
     <td width=40% align=center>
         列表二
     </td>
   </tr>         
   <tr>
      <td width=40% align=center>
          <form name=form1>
            <select size=10  name=select1 multiple>
              <option value=1>sample string 1</option>
              <option value=2>sample string 2</option>
              <option value=3>sample string 3</option>
              <option value=4>sample string 4</option>
              <option value=5>sample string 5</option>
              
            </select>
          </form>
      </td>       
      <td valign=middle width=20% align=center>
          <br>
          <br>
           <input type=button name=btngoleft onclick="go_left();" value="<<">
          <br>
          <br>              
           <input type=button name=btngoright onclick="go_right();" value=">>">
          <br>
          <br>
      </td>                
      <td width=40% align=center>
          <form name=form2>
            <select size=10 length=40 name=select2 multiple >
           </select>
          </form>
      </td>              
  </tr>
</table>           

<script language=javascript>
  //将列表框1中的选定部分移到列表框2中
  function go_left()
     {
       
       for (i=0 ; i<=form2.select2 .options .length -1 ; i++)
          {
            //如果这条被选中则复制倒列表框1中
            if (form2.select2 .options [i].selected)
              {
                var element = window.option.create (form2.select2.options [i].text,
                               form2.select2 .options[i].value,0);
                form1.select1.add (element);
              }  
              
          }  
       var j = 0 ;  
       
       //删除选定记录
       for (i=0 ; i< form2.select2 .options .length ; i++)
          {
            if (form2.select2 .options [i].selected)
              {
                form2.select2.remove(i);
                i = i – 1 ;
              }  
              
          }  
    }
    
  //将列表框2中的选定部分移到列表框1中
  function go_right()
     {
       for (i=0 ; i<=form1.select1 .options .length -1 ; i++)
          {
            if (form1.select1 .options [i].selected )
              {
                var element = window.option.create (form1.select1.options [i].text,
                               form1.select1 .options[i].value,0);
                form2.select2.add (element);
              }  
              
          }  
       for (i=0 ; i< form1.select1 .options .length ; i++)
          {
            if (form1.select1 .options [i].selected )
              {
                form1.select1.remove(i);
                i = i – 1 ;
              }  
              
          }  
      
          
     }
    
</script>              

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 一段有趣并且实用的程序–利用javascript和dhtml实现两个列表框中内容的移动。(代码见内,把它存为一个…
分享到: 更多 (0)

相关推荐

  • 暂无文章