用JS做了个ListBox的简单功能

 

        这段时间在项目组都是做静态页面,都是些复制粘贴的活,难得碰到个稍微有点难度的页面。后来看到这个页面还不错,可以自己做做看,虽然公司已经有这样的组件,但不想用,反正没什么事,就当多学学JS好了。

        页面效果如下:

 

        代码也贴出来跟大家分享:

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
  5. <title></title>
  6. </head>
  7. <body>
  8. <script language="JavaScript" type="text/javascript">
  9. <!--
  10. function addIt(){
  11.    var input = document.getElementById("input");
  12.    var output = document.getElementById("output");
  13.    for(i = 0; i < input.length; i ++ )   {
  14.       if(input[i].selected == true)      {
  15.          if( output.length == 0){
  16.             var option = new Option();
  17.             option.text = input[i].innerText;
  18.             output.add(option);
  19.          }
  20.          var isExist = false;
  21.          for(j = 0; j < output.length; j ++ ){
  22.             if (output[j].text ==  input[i].innerText){
  23.                isExist = true;
  24.                break;
  25.             }
  26.          }
  27.          if (isExist == false){
  28.             var option = new Option();
  29.             option.text = input[i].innerText;
  30.             output.add(option);
  31.          }
  32.       }
  33.    }
  34. }
  35. function deleteIt(){
  36.     var output = document.getElementById("output");
  37.     for(i = 0; i<output.length; i++){
  38.         if (output[i].selected == true){
  39.             output.options.removeChild(output[i--]);
  40.         }
  41.     }
  42. }
  43. // -->
  44. </script>
  45. <table width="80%" border="0" align="center" style="margin-top:20px;">
  46.   <tr>
  47.     <td align="right">
  48.       <select name="input" size="10" multiple="multiple" id="input" style="width:200px; font-size:16px">
  49.         <option>美元/英镑</option>
  50.         <option>美元/港币</option>
  51.         <option>美元/新加坡元</option>
  52.         <option>美元/日元</option>
  53.         <option>美元/加拿大元</option>
  54.         <option>美元/欧元</option>
  55.       </select>
  56.     </td>
  57.     <td align="center">
  58.       <p>
  59.         <input type="button" name="Submit" value="增  加" onclick="addIt()"/>
  60.       </p>
  61.       <p>
  62.         <input type="button" name="Submit2" value="删  除" onclick="deleteIt()"/>
  63.       </p>
  64.     </td>
  65.     <td>
  66.       <select name="output" size="10" multiple="multiple" id="output" style="width:200px; font-size:16px">
  67.       </select>
  68.     </td>
  69.   </tr>
  70. </table>
  71. </body>
  72. </html>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值