Rendering a hierarchy of “OPTION”s in a “SELECT” tag

后端 未结 7 1895
庸人自扰
庸人自扰 2020-12-03 05:13

My problem is HTML and CSS related. I have a hierarchy type structure that I want to display inside a list. The hierarchy contains Countries, States and Cities (it is three

7条回答
  •  南方客
    南方客 (楼主)
    2020-12-03 05:41

    Just for the sake of visitors, I feel I should share this solution I devised: http://jsfiddle.net/n9qpN/

    Decorate the options with the level class

    
    

    We can now use jQuery to reformat the content of the select element

    $(document).ready(
    function(){
       $('.level_2').each(
            function(){
                $(this).text('----'+$(this).text());
            }
       );
    
       $('.level_3').each(
            function(){
                $(this).text('---------'+$(this).text());
            }
       );
    
     }
    );
    

    This can be extended to any level

提交回复
热议问题