jquery remove/add select options after cloning select list

后端 未结 1 1617
青春惊慌失措
青春惊慌失措 2021-01-24 00:34

I need to be able to clone a drop down list and filter only those options that were NOT yet selected in the group of select lists.

For example, having the following:

相关标签:
1条回答
  • 2021-01-24 00:43

    This seems to do what you want: http://jsfiddle.net/infernalbadger/SKVSu/1/

    $('#clone').click(function() {
        var original = $('select.selService:eq(0)');
        var allSelects = $('select.selService');
        var clone = original.clone();
    
        $('option', clone).filter(function(i) {
            return allSelects.find('option:selected[value="' + $(this).val() + '"]').length;
        }).remove();
    
        $('#target').append(clone).append('<br />');
    });
    
    0 讨论(0)
提交回复
热议问题