SoFunction
Updated on 2025-02-28

BootStrap selectpicker background dynamically binds data

This article shares with you the method of dynamically binding data in the BootStrap selectpicker background for your reference. The specific content is as follows

Part of html code

<select class="selectpicker" multiple>      
</select>

This is a drop-down multi-box, and now you need to dynamically add drop-down options to it.

js code

<script type="text/javascript">
      getOption();
      function getOption(){
        $.ajax({
          type:"get",
          url:"",
          async:true,
          success:function (data) {
            var str = "";
            for(var i = 0;i<;i++){
              str+='<option>'+data[i].value+'</option>'
            }
            $(".selectpicker").html(str);
            
            $(".selectpicker" ).selectpicker('refresh');
          }
        });
      }
</script>

The key is $(".selectpicker" ).selectpicker('refresh');

Without this sentence, data cannot be bound.

The above is all the content of this article. I hope it will be helpful to everyone's study and I hope everyone will support me more.