How to set selected value on select using selectpicker plugin from bootstrap

前端 未结 18 2242
日久生厌
日久生厌 2020-11-27 13:29

I\'m using the Bootstrap-Select plugin like this:

HTML:


                        
    
提交评论

  • 2020-11-27 14:12

    Well another way to do it is, with this keyword, you can simply get the object in this and manipulate it's value. Eg :

    $("select[name=selValue]").click(
        function() {
            $(this).val(1);
        });
    
    0 讨论(0)
  • 2020-11-27 14:12

    use this and it's gonna work:

     $('select[name=selValue]').selectpicker('val', 1);
    
    0 讨论(0)
  • 2020-11-27 14:14

    Based on @blushrt 's great answer I will update this response. Just using -

    $("#Select_ID").val(id);
    

    works if you've preloaded everything you need to the selector.

    0 讨论(0)
  • 2020-11-27 14:16
    $('.selectpicker').selectpicker('val', YOUR_VALUE);
    
    0 讨论(0)
  • 2020-11-27 14:18
    $('#mybutton').click(function(){
       $('select[name=selValue]').val(1);
       $('select[name=selValue]').change();
    });
    

    This worked for me.

    0 讨论(0)
  • 提交回复
    热议问题