1.引入js和css:
<link href="<c:url value="/resources/lib/bootstrap-select/bootstrap-select.css"/>" rel="stylesheet">
<script src="<c:url value="/resources/lib/bootstrap-select/bootstrap-select.js"/>"></script>
2.html页面
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<style type="text/css">
.btn-default {
background-color: #FFF;
border-color: #c2c2c2;
color: #000;
}
.btn-default:hover, .btn-default:focus, .btn-default:active, .btn-default.active, .open .dropdown-toggle.btn-default {
background-color: #FFF;
/* border-color: #bababa;*/
color: #000;
}
.bootstrap-select > .dropdown-toggle {
width: 158.5%;
}
.bootstrap-select.btn-group .dropdown-menu {
min-width: 158.5%;
}
</style>
<script type="text/javascript">
function codeChange() {
var wareCode=$('#anmesel_menu3').val();
var rackCode=wareCode+"-";
$("#rackcode").val(rackCode);
}
if($('#rackCodeOne').val()==''){
var wareCode=$('#anmesel_menu3').val();
var rackCode=wareCode+"-";
$("#rackCode").val(rackCode);
}else {
$('#rackCodeOne').val('');
}
</script>
<input id="id" name="id" value="${storageRack.id}" hidden/>
<%--<div class="col-lg-10">
<select class="selectpicker" data-live-search="true">
<option>Mustard</option>
<option>Ketchup</option>
<option>Relish</option>
</select>
</div>--%>
<div class="form-group">
<label class="col-sm-3 control-label" for="anmesel_menu3" style="margin-left: -1.5%;">仓库编码:</label>
<div class="col-sm-8" style="margin-left: 1.7%">
<select id="anmesel_menu3" name="war_id" class="selectpicker" data-live-search="true" οnchange="codeChange()">
<c:forEach items="${warehouseList}" var="warehouse">
<option value="${warehouse.code}"
<c:if test="${warehouse.code == storageRack.war_id}">selected="selected"</c:if>>
${warehouse.code}
</option>
</c:forEach>
</select>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">货架编码:</label>
<div class="col-sm-8">
<input id="rackcode" name="code" type="text" class="form-control" required value="${storageRack.code}">
<input type="hidden" id="rackCodeOne" name="code" value="${storageRack.code}" />
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">货架名称:</label>
<div class="col-sm-8">
<input id="name" name="name" type="text" class="form-control" required value="${storageRack.name}">
</div>
</div>
<script>
$('.selectpicker').selectpicker('show');
</script>