Selectpicker Lado box Ajax Async or Advance assignment = "Default value

Source: Internet
Author: User

Bootstrap Select Multi-select drop-down box assignment value

Success:function (data) {    var oldnumber = new Array ();    $.each (data, function (i) {            oldnumber.push (data[i].id);    });    $ (' #editcolor. Selectpicker '). Selectpicker (' Val ', oldnumber);//select    $ (' #editcolor. Selectpicker ') by default. Selectpicker (' Refresh ');}

Above is Ajax get the default value, remember Selectpicker is through the ID to operate,

<div class= "col-md-8" id= "Editcolor" >    <select placeholder= "Please select Color" id= "selectpickerallstr"            name= " Selectpickerallstr "            class=" Selectpicker show-tick form-control "data-style=" btn-success "multiple            Data-live-search= "true" >    </select></div>

You can refer to an article in front of me, I'll post it again get the code

Select color var loadtemplatecolor = function () {    $.ajax ({        type: ' GET ',        url:root + '/mycolor ',        success: function (data) {            var data = eval (data);            $.each (data, function (i) {                    $ ("<option value=" "+ data[i].id +" ' > "+ data[i].text +" </option> ")                                                                    . App EndTo (". Selectpicker");            });            $ ('. Selectpicker '). Selectpicker ({          //I am a one-time assignment for all selectpicker operations, if you want to assign a value individually, OK, then assign the value:          //appendto ("# Editcolor. Selectpicker "), in this case, on your select element cover a div,         //with the DIV ID to mark the selectpicker you want to manipulate, that is, you want to manipulate the SELECT element tag           style: ' Btn-info ',                size:8            })}}    );

Fix a value at a time:

$ (' #editcolor. Selectpicker '). Selectpicker (' Val ', 1);//Selected by default
$ (' #editcolor. Selectpicker '). Selectpicker (' refresh ');

A lot of values are assigned at once:

Success:function (data) {    var oldnumber = new Array ();    $.each (data, function (i) {            oldnumber.push (data[i].id);    });    $ (' #editcolor. Selectpicker '). Selectpicker (' Val ', oldnumber);//select    $ (' #editcolor. Selectpicker ') by default. Selectpicker (' Refresh ');}

Dynamically assigned values

<select id= "filetype" name= "filetype" class= "Selectpicker show-tick dropup" data-live-search= "true" onchange= " Filetypechange (); " ></select>

Initialize call Getdata4select ("filetype", "file_type");

/**
* Query the dictionary data according to the dictionary type for bootstrap select to use
* @param ID
* @param dicttype
*/
function Getdata4select (id,dicttype) {
var url = '/yh/com/dominsoft/act/yhtypehandleact/getitemtype.act?type= ' +dicttype;
var json = Getjsonrs (URL);
if (json.rtstate = = "0") {
var rtdata = Json.rtdata;
var typedata = Rtdata.typedata;
JQuery (' # ' +id). Append ("<option value=" > Please select </option> ");
for (var i = 0; i < typedata.length; i++) {
JQuery (' # ' +id). Append ("<option value=" + Typedata[i].typeid + ">" + Typedata[i].typedesc + "</option>");
}
}
JQuery (' # ' +id). Selectpicker ();
}

Selectpicker Lado box Ajax Async or Advance assignment = "Default value

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.