简体   繁体   English

jQuery将选择框选择的值复制到另一个选择框

[英]jQuery copy selectbox selected value to another selectbox

Is it possible to copy a selected option from the first dropdown to another using Jquery and disallowing the user from copying the SAME option ? 是否可以使用Jquery将选定的选项从第一个下拉列表复制到另一个下拉列表,并禁止用户复制SAME选项?

在此处输入图片说明

HTML Markup HTML标记

<select id="one" multiple="multiple">
    <option>one</option>
    <option>two</option>
    <option>three</option>
</select>

<select id="two" multiple="multiple">

</select>

Jquery jQuery的

$('#one option').click(function() {
   $(this).clone().appendTo("#two");
});

FIDDLE 小提琴

Yes: 是:

var option = $("#idOfSelect option:eq(0)"); //eq 0 targets the first option, change to what you need
$("#idOfOtherSelect").append(option);

Like this: 像这样:

$('#first').change(function(){

    $('#second').append("<option value="+$(this).val()+">"+$("#first option:selected").text()+"</option>")

})

FIDDLE EXAMPLE 例子

Example: 例:

$("#copy").on("click", function(e) {
    e.preventDefault();
    $("#select1 option:selected").clone().appendTo($("#select2"));
});

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM