简体   繁体   English

如何将 select 标签中的选项传递给另一个 select 标签?

[英]How can I pass an option in a select tag to another select tag?

I have a list of options in a select tag, then an element to pass a selected option to others select tag.我在 select 标记中有一个选项列表,然后是一个将选定选项传递给其他 select 标记的元素。 My 'select' is in multiple forms so each option is displayed as a line of text.我的“选择”在多个 forms 中,因此每个选项都显示为一行文本。 What I want to achieve is after I click on an option, then click on the declare variable with 'onclick' function, that option will be pass to others select tag.我想要实现的是在我单击一个选项后,然后单击带有'onclick' function 的声明变量,该选项将传递给其他 select 标记。

My HTML:我的 HTML:

<div class="container row" style="display:flex;" id="employeeTransfer">
   <label class="col-3 col-md-3 col-lg-3 col-sm-3 pb-sm-5 pb-5">Người nhận</label>
   <select id="employeeDisplay" class="col-3 col-lg-3 col-sm-3 form-control" multiple style="margin-left:12px;">
      <option id="1">Bùi Thị Bưởi</option>
      <option id="2">Tằm Thị Dâu</option>
      <option id="3">Cao Văn Bách</option>
   </select>
   <div class="col-1 col-md-1 col-lg-1 col-sm-1 pb-sm-5 pb-5">
      <ul style="list-style-type:none;margin:0;padding:0; padding-top:40%; padding-left:30%;">
         <li id="sendEmployee" onclick="processEmployee()">⫸</li>
         <li id="returnEmployee">⫷</li>
      </ul>
   </div>
   <select id="employeeProcess" class="col-3 col-md-3 col-lg-3 col-sm-3 pb-sm-5 pb-5 form-control" multiple>
   </select>
</div>
<br />

Very simple task - just take the currently selected option from the first drop-down and create a new option in the second select:非常简单的任务 - 只需从第一个下拉列表中选择当前选择的选项,然后在第二个 select 中创建一个新选项:

function processEmployee()
{
  var select_1 = document.getElementById('employeeDisplay');
  var select_2 = document.getElementById('employeeProcess');
  var option, i, j, found;

  for (i = 0; i < select_1.options.length; i++)
  {
    if (select_1.options[i].selected)
    {
      found = false;
      for (j = 0; j < select_2.options.length; j++)
      {
        if (select_2.options[j].value == select_1.options[i].value)
        {
          found = true;
          break;
        }
      }
      if(!found)
      {
        select_2.add(new Option(select_1.options[i].text,select_1.options[i].value));
      }
    }
  }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 当我选择另一个选择标记HTML的某个选项时,如何自动更改选择标记选项的值列表<select> - How to automatically change the value list of option of select tag when i select the certain option of another select tag HTML <select> 如何在选择标签中选择选项 - How to select option in select tag 如何在动态创建的选择标记中添加一个空选项? - How can I add an empty option in a select tag created dynamically? 从另一个选择中更改选择标记中的选项 - Change option in select tag from another select 选择选项后如何添加另一个选项标签? - How to add another option tag after you select a option? 如何从 reactjs 中 select 标签(主)的 onchange 事件更新另一个 select 标签(子)? - How can i update another select tag(sub) from an onchange event of select tag(main) in reactjs? 当我有五个具有相同选项和值的select时,如何从另一个select标记中删除一个选中的选项? - How to remove a selected option from another select tag when i have five select with same options and values? (Vue.js) 如何使用数据中的数值数组中的选项标签填充选择标签? - (Vue.js) How can I populate the select tag with option tag from array of number values in data? 如何使用 JavaScript\\JQuery 使用选择标记的选定选项的值设置隐藏输入标记的值? - How can I set the value of an hidden input tag with the value of the selected option of a select tag using JavaScript\JQuery? 根据另一个选择标签选择的值选择标签选项 - Select tag option depending on another select tag selected value
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM