使用Jquery从select中筛选重复选项

时间:2016-11-08 10:54:28

标签: javascript php jquery

问题:我有2个选项名称 尝试 restrock 我在 尝试 选项中将 macbook pro 添加到指定的框中,之后我转到 restock 选项添加相同的产品调用 macbook pro ,然后系统将允许用户再次添加。那么,当 尝试 选项已经 macbook pro 然后当用户尝试再次添加 时,我如何检查它? restock 选项系统会自动从 尝试 选项中删除 mac book pro 并添加新的 macbook pro restock 选项???

fdsadsa

enter image description here

enter image description here

enter image description here

enter image description here

我写的代码

function addSelectedProducts(row_lab) {
    $('#product_placeholder'+row_lab+' :selected').each(function() {

        $(this).remove();

        $('#related'+row_lab+' option[value=\'' + $(this).attr('value') + '\']').remove();

        $('#related'+row_lab).append('<option value="' + $(this).attr('value') + '">' + $(this).text() + '</option>');

        $('#product_added input[value=\'' + $(this).attr('value') + '\']').remove();

        var featured_string = document.getElementById('imploding_feature'+row_lab).value;

        var sear_exist = featured_string.search('/'+$(this).attr('value')+'/');
        if(sear_exist == -1){
            featured_string = featured_string + $(this).attr('value') + ',';
            featured_string = featured_string.replace(/^,/, '');
            $('#imploding_feature'+row_lab).val(featured_string);
        }

    });
}

0 个答案:

没有答案
相关问题