Jquery adding and removing items from listbox

后端 未结 9 939
粉色の甜心
粉色の甜心 2021-02-03 13:13

I\'ve created this fiddle, it allows the user to click on either art or video, dynamically populating the the second listbox with the list associated with those selections. Ther

9条回答
  •  执念已碎
    2021-02-03 13:23

    Ok to fix your add function just add the following if condition::

    if($("#SelectedItems option:contains("+$(this).text()+")").length<=0)                
       inHTML += '';
    

    to remove items::

    $('#remove').click(function () {
        $("#SelectedItems option:selected").each(function () {
           $(this).remove();
        });
    });
    

    here is the example after i updated it jsfiddle

提交回复
热议问题