zoukankan      html  css  js  c++  java
  • 把一个下拉框中的选项添加到另一个中

     1<html>
     2 <body>
     3 <form name="aa">
     4  <table align="center">
     5   <tr>
     6    <td>
     7     <select name="xuanze" size="6"  style="80px">
     8      <option value="海淀">海淀</option>
     9      <option value="朝阳">朝阳</option>
    10      <option value="东城">东城</option>
    11      <option value="西城">西城</option>
    12      <option value="宣武">宣武</option>
    13      <option value="丰台">丰台</option>
    14     </select>
    15    </td>
    16    <td align="center">
    17     <input type="button" value="添加>>" onclick="javascript:add()"/>
    18     <br>
    19     <input type="button" value="<<删除" onclick="javascript:del()"/>
    20    </td>
    21    <td>
    22     <select name="xuanzhong" size="6" style="80px"></select>
    23    </td>
    24   </tr>
    25
    26  </table>
    27</form>
    28 </body>
    29 <script type="text/javascript">
    30         function isexist(va){
    31           var ee = false;
    32           for(var i=0;i<document.aa.xuanzhong.options.length;i++)
    33             if(document.aa.xuanzhong.options[i].value==va)
    34              {  ee=truebreak;}
    35           return ee;
    36         }

    37  function add(){//添加
    38     for(var i=0;i<document.aa.xuanze.options.length;i++)
    39        if(document.aa.xuanze.options[i].selected) {
    40          if(!isexist(document.aa.xuanze.options[i].value)) //是否已经添加??
    41          document.aa.xuanzhong.options[document.aa.xuanzhong.options.length]
    42          = new Option(document.aa.xuanze.options[i].value,document.aa.xuanze.options[i].text);
    43        }

    44  }

    45  function del(){
    46     for(var i=document.aa.xuanzhong.options.length-1;i>=0;i--)
    47       if(document.aa.xuanzhong.options[i].selected)
    48         document.aa.xuanzhong.options[i] = null//删除一个项目
    49 
    50  }

    51 </script>
    52</html>
  • 相关阅读:
    leetcode 33. Search in Rotated Sorted Array
    leetcode 28. Implement strStr()
    Scala函数
    布隆过滤器相关知识
    Storm 流式计算框架
    java高并发核心类 AQS(Abstract Queued Synchronizer)抽象队列同步器
    操作系统类型&操作系统结构&现代操作系统基本特征
    Kafka笔记
    Redis shell
    Lucene笔记
  • 原文地址:https://www.cnblogs.com/liuhaitao/p/1229681.html
Copyright © 2011-2022 走看看