How to dynamic filter options of <select > with jQuery?

前端 未结 12 615
轮回少年
轮回少年 2020-11-29 18:54



        
12条回答
  •  野性不改
    2020-11-29 19:08

    I'm not sure why you have more than one option with the same value, but this works

    $(document).ready(function() {
      $('input').change(function() {
        var filter = $(this).val();
        $('option').each(function() {
          if ($(this).val() == filter) {
            $(this).show();
          } else {
            $(this).hide();
          }
          $('select').val(filter);
        })
      })
    })
    
    
    

提交回复
热议问题