Sort a table by drop down values (simplify my code)

前端 未结 4 1946
小蘑菇
小蘑菇 2021-01-23 17:37

I have a table. I want the user to be able to be able to filter the table by the option they pick in a given drop down. I have it working, but it\'s messy and hard to add new ro

4条回答
  •  醉梦人生
    2021-01-23 18:06

    Please find the refactored code "http://jsfiddle.net/5fZv7/3/" here and the code snippet is as below..

    html code:

    
    

    and the javascript code:

     $(document).load(function () {
       $('#selectFilter').change(function () {
         $(".all").hide();
         $("." + $(this).find(":selected").attr("id")).show();
       });
     });
    

    Hopes this helps you to maintain the code easily and efficiently.

    提交回复
    热议问题
    cats
    cats 2
    dogs
    birds