解决bootstrap-select下拉框多选,无法回选问题

版权声明:本文为博主原创文章,未经博主允许不得转载。否则,吔屎伺候。 https://blog.csdn.net/guowujun321/article/details/79421180

事例代码如下:

html:

<select id="useseason" name="season" class="selectpicker bla bla bli" multiple data-live-search="true">
      <option value="1">1</option>  
      <option value="2">2</option> 
</select>

js:

$(function(){
            $('.selectpicker').selectpicker();
            var season = '$!season';		//回选的数据
            if (season !=null && season  !='') {
                var seasonlist = season.replace(/ /g,'').split(",");
                $('.selectpicker').selectpicker('val',seasonlist);
                $('.selectpicker').selectpicker('render');
            }
        });

由于使用了velocity模板,所以在js里可用$!season取到数据。延伸个问题,对于velocity模板,独立引用的js文件无法通过$取到后台返回的数据。只能通过页面的如下形式

<script>
   ......
 </script>

在js里使用$。


猜你喜欢

转载自blog.csdn.net/guowujun321/article/details/79421180