Trying to set data-live-search to select-picker

非 Y 不嫁゛ 提交于 2021-01-29 07:49:35

问题


selectpicker

$('.selectpicker').selectpicker();
$("#s1").addClass("btn-sm");
//set to current value$("#s1").selectpicker('val', picker[0]["f_name"]);
$("#s1").selectpicker("refresh");

select picker css

<div id="input1" style="margin-bottom: 50px">
    <div class="pull-left" style="width: 250px;">
        <select class="selectpicker" data-live-search="true" id="s1"> 
        </select>

This is my code. I want to set a search in my select picker. What should I do?


回答1:


<div class="live-search" >
    <select class="selectpicker" data-live-search="true" >
       <option data-tokens="text" >text</option>                               
     </select>
 </div>

You have to add src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.13.2/js/bootstrap-select.min.js"




回答2:


selectpicker function should be on ready method of jquery.

Also try

 $('.selectpicker').selectpicker({
    liveSearch: true
 });

instead of data-live-search="true" in html.



来源:https://stackoverflow.com/questions/41717660/trying-to-set-data-live-search-to-select-picker

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!