[英]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选项?
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>")
})
Example: 例:
$("#copy").on("click", function(e) {
e.preventDefault();
$("#select1 option:selected").clone().appendTo($("#select2"));
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.