Delete duplicate entries from a select box

前端 未结 4 1497
梦谈多话
梦谈多话 2021-01-05 17:18

How would I, using jQuery, remove the dups

        
        
4条回答
  •  礼貌的吻别
    2021-01-05 17:43

    The easiest way that came into my mind was using siblings

    $("select>option").each( function(){
    
     var $option = $(this);  
    
     $option.siblings()
           .filter( function(){ return $(this).val() == $option.val() } )
           .remove()
    
    
    })
    

提交回复
热议问题