[英]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.