简体   繁体   English

jQuery的克隆选择框没有选择的选项

[英]jquery cloning select box without selected option

Need to clone select box from previous one ( ie, add select box 'n' number of time from the previous one ) But when I added each time, all the previously selected options should not be available in the cloned select box list. 需要从上一个克隆选择框(即,从前一个添加选择框'n'的次数)但是,当我每次添加时,所有先前选择的选项在克隆的选择框列表中都不可用。

$('.field_select_box_list').each(function(){
        $(this).find('option:selected').remove();
});

This code removes the parent select boxes selected option too.. but I want remain them to have the selected option. 这段代码也删除了父选择框的选定选项。.但是我希望保留它们具有选定的选项。

any help. 任何帮助。

Your clone code can just do something like 您的克隆代码只能做类似的事情

$('el').clone().find('option:selected').remove().end()

The .end() causes the selector to return to being $('el') rather than the filtered option:selected selector, so you can continue running things like .appendTo() etc without needing to break the chain. .end()会使选择器返回到$('el')而不是已过滤的option:selected选择器,因此您可以继续运行.appendTo()类的东西而无需打断链。

I think you need use one select_box original , hidden it. 我认为您需要使用一个select_box original ,将其隐藏。 Then you can remove with select_box second not hidden or add more element from select_box original . 然后,您可以使用select_box第二个未隐藏的元素删除它,或者从select_box original添加更多元素。

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

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