欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

bootstrap中selectpicker下拉框使用方法實(shí)例

 更新時(shí)間:2018年03月22日 11:55:16   作者:Big丶Fine  
這篇文章主要給大家介紹了關(guān)于bootstrap中selectpicker下拉框使用的相關(guān)資料,文中通過(guò)示例介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧。

前言

最近一直在用bootstrap 的一些東西,寫(xiě)幾篇博客記錄下。。。。

bootstrap selectpicker是bootstrap里比較簡(jiǎn)單的一個(gè)下拉框的組件,先看效果如下:

附上官網(wǎng)api鏈接,http://silviomoreto.github.io/bootstrap-select/.

下拉框的使用上基本操作一般是:?jiǎn)芜x、多選、模糊搜索、動(dòng)態(tài)賦值等,下面來(lái)看如何使用:

使用方法如下

1、首先需要引入的css和js:

    bootstrap.css
    bootstrap-select.min.css
    jquery-1.11.3.min.js
    bootstrap.min.js
    bootstrap-select.min.js

2、js代碼如下:

$(function() { 
  $(".selectpicker").selectpicker({ 
   noneSelectedText : '請(qǐng)選擇'//默認(rèn)顯示內(nèi)容 
  }); 
//數(shù)據(jù)賦值 
var select = $("#slpk"); 
select.append("<option value='1'>香蕉</option>"); 
select.append("<option value='2'>蘋(píng)果</option>"); 
select.append("<option value='3'>橘子</option>"); 
select.append("<option value='4'>石榴</option>"); 
select.append("<option value='5'>棒棒糖</option>"); 
select.append("<option value='6'>桃子</option>"); 
select.append("<option value='7'>陶子</option>"); 
//初始化刷新數(shù)據(jù) 
 $(window).on('load', function() { 
  $('.selectpicker').selectpicker('refresh'); 
 }); 
}); 

3、jsp內(nèi)容:

<select id="slpk" class="selectpicker" data-live-search="true" multiple></select> 

設(shè)置multiple時(shí)為多選,data-live-search="true"時(shí)顯示模糊搜索框,不設(shè)置或等于false時(shí)不顯示。

4、其他方法:

獲取已選的項(xiàng):

var selectedValues = [];  
slpk:selected").each(function(){ 
selectedValues.push($(this).val()); 
}); 

選擇指定項(xiàng)(編輯回顯使用):

        單選:$('.selectpicker').selectpicker('val', ‘列表id');

        多選:var arr=str.split(','); $('.selectpicker').selectpicker('val', arr);

5、附上我的源碼,下拉數(shù)據(jù)通過(guò)ajax從后臺(tái)獲?。?/strong>

$(function() { 
  $(".selectpicker").selectpicker({ 
   noneSelectedText : '請(qǐng)選擇' 
  }); 
  $(window).on('load', function() { 
   $('.selectpicker').selectpicker('val', ''); 
   $('.selectpicker').selectpicker('refresh'); 
  }); 
  //下拉數(shù)據(jù)加載 
  $.ajax({ 
   type : 'get', 
   url : basePath + "/lictran/tranStation/loadRoadForTranStationDetail", 
   dataType : 'json', 
   success : function(datas) {//返回list數(shù)據(jù)并循環(huán)獲取 
    var select = $("#slpk"); 
    for (var i = 0; i < datas.length; i++) { 
     select.append("<option value='"+datas[i].ROAD_CODE+"'>" 
       + datas[i].ROAD_NAME + "</option>"); 
    } 
    $('.selectpicker').selectpicker('val', ''); 
    $('.selectpicker').selectpicker('refresh'); 
   } 
  }); 
 }); 

總結(jié)

以上就是這篇文章的全部?jī)?nèi)容了,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,如果有疑問(wèn)大家可以留言交流,謝謝大家對(duì)腳本之家的支持。

相關(guān)文章

最新評(píng)論