[英]JS make a list of multiple select-options in textField
$().ready(function() {
$('#add').click(function() {
return !$('#select1 option:selected').remove().appendTo('#select2');
});
$('#remove').click(function() {
return !$('#select2 option:selected').remove().appendTo('#select1');
});
});
这两个函数将所选选项从一个多重选择移动到另一个。 我需要在隐藏的输入类型中创建一个包含所有添加选项值(在#select2中)的列表。 每次调用其中一个函数时,都应更新此输入。
这应该有所帮助
var yourInput = $('#IdOfYourInput');
$('#add').click(function() {
var opt = !$('#select1 option:selected').remove().appendTo('#select2');
yourInput.val($('#select2 option').map(function(){return this.value;}).get().join(','));
return opt;
});
删除类似:
$('#remove').click(function() {
var opt =$('#select2 option:selected').remove().appendTo('#select1');
yourInput.val($('#select2 option').map(function(){return this.value;}).get().join(','));
opt.appendTo('#select1');
return opt;
});
我希望这是你的目标......
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.