1. page code:
Page introduction:
bootstrap-select.min.css和
bootstrap-select.min.js、
defaults-zh_CN.min.js file, and initialize the drop-down option box.
Attribute searches with drop down box style: data-live-search = "true"
Drop-down box option multiple-choice property: multiple
<div class="col-xs-6 col-sm-6 col-md-4 col-lg-4 clearfix "> <label class="col-xs-4 col-sm-4 control-label required">车班名称:</label> <div class="col-xs-8 col-sm-8"> <div class="input-group"> <select name="shuttleBusId" class="form-control select-picker" data-live-search="true" multiple> <option value=""the Option</- Please select ->> <option th:each="iterator : ${vehicleShiftList}" th:value="${iterator.idTrafficVehicleShift}" th:text="${iterator.vehicleShiftName}"> </option> </select> </div> </div> </div>
2.js Code // the SELECT multiple choice can do more than set the selected item, use maxlength
// JS code as follows: // Get all said drop-down box to select items var checkParam = $ ( '# SELECT-type') Find. ( 'Option: Selected' ); // check the ID set var CheckId = []; // selected text value set var checkText = []; for ( var I = 0; I <checkParam.length; I ++ ) { checkId.push (checkParam [I] .Value); } for ( var I = 0; I <checkParam.length; I ++ ) { checkText.push (checkParam [I] .textContent); } // array to a string var IDS = checkId.join ( ',' ); var= checkText.join text ( ',' );
// 1. define objects, and to set the property name and value --------------------------- ------------------ // determines whether the selected iF (checkParam.length> 0 ) {
var = hilidayFlag. 1; // defined parameter object passed, and assign var the params = { holidayFlag: holidayFlag, shuttleBusId: IDS,
shuttleBusName: text } }
// 2. define objects, and to set the attribute names and values ------------------------ ---------------------
// Get the value of the form
var User = {};
// get the value of all the pages in the form in the form of name-value
. FormData var = $ ( 'the addForm #') serializeArray ();
formData.forEach (function (Item) {
User [ item.name, for] = item.value;
})
PS: gets converted into an array of objects form results