Materialize select not working append option with

后端 未结 2 1319
攒了一身酷
攒了一身酷 2021-01-14 11:09

I use materialize css for my project, i have problem when i want to append option in matrialize select with ajax. I\'ve following this answer How to dynamically modify <

2条回答
  •  不知归路
    2021-01-14 11:35

     $(document).ready(function() {
        $('select').material_select();
     });
     
     $(document).on('change','#select_1', function(){
         get_selected();         
    })
    
    
    function get_selected(){
         var data=[{id:1,name:"ABC"},{id:2,name:"XYZ"},{id:3,name:"PQR"}];
         
         var Options="";
        $.each(data, function(i, val){ 
          Options=Options+"";
      });
      $('#select_2').empty();
      $('#select_2').append(Options);
      $("#select_2").material_select()
    } 
    
    
    
      
    
    
      
        
    

提交回复
热议问题