您好,登錄后才能下訂單哦!
本篇文章給大家分享的是有關(guān)使用bootstrap怎么實(shí)現(xiàn)一個(gè)多個(gè)下拉框同時(shí)搜索功能,小編覺(jué)得挺實(shí)用的,因此分享給大家學(xué)習(xí),希望大家閱讀完這篇文章后可以有所收獲,話不多說(shuō),跟著小編一起來(lái)看看吧。
1.第一個(gè)下拉框代碼
<div class="btn-group col-sm-3 col-xs-6 util-btn-margin-bottom-5 quick-search"> <!--快速查詢--> <div class="input-group"> <span class="input-group-addon"><i class="fa fa-search"></i></span> <select data-filter-type="2" name="copyfrom" class="form-control select2" data-validate="notempty" data-field="name" data-placeholder="搜索數(shù)據(jù)資源"> <option value="">請(qǐng)選擇數(shù)據(jù)資源</option> <optgroup label="UNESCO二類中心"> <#list data.copyfromList as entity> <#if (entity.type?? && entity.type == '1')> <option value="${entity.alias!}" <#if (param.copyfrom?? && param.copyfrom == entity.alias)>selected</#if>>${entity.alias!}</option> </#if> </#list> </optgroup> <optgroup label="科技動(dòng)態(tài)與進(jìn)展"> <#list data.copyfromList as entity> <#if (entity.type?? && entity.type == '7')> <option value="${entity.alias!}" <#if (param.copyfrom?? && param.copyfrom == entity.alias)>selected</#if>>${entity.alias!}</option> </#if> </#list> </optgroup> <optgroup label="其他"> <#list data.copyfromList as entity> <#if (entity.type?? && entity.type == '8')> <option value="${entity.alias!}" <#if (param.copyfrom?? && param.copyfrom == entity.alias)>selected</#if>>${entity.alias!}</option> </#if> </#list> </optgroup> </select> </div> </div>
2.第二個(gè)下拉框代碼
<div class="btn-group col-sm-3 col-xs-6 util-btn-margin-bottom-5 quick-search"> <!--快速查詢--> <div class="input-group"> <span class="input-group-addon"><i class="fa fa-search"></i></span> <select data-filter-type="2" name="cid" class="form-control select2" data-validate="notempty" data-field="name" data-placeholder="搜索欄目名稱"> <option value=""></option> <#list data.categories as entity> <option value="${entity.id}" <#if (param.cid?? && param.cid == entity.id)>selected</#if>>${entity.id} - ${entity.name}</option> </#list> </select> </div> </div>
3.后臺(tái)js代碼(url 參數(shù)整理)
bindEvents:function(){ var self = this, dom = self.element; $('select[name="copyfrom"]', dom).change(function(event){ self.params.copyfrom = $(this).val(); var url = self.formatParams(self.params); window.location.href = "cekasp_article.htm" + url; }); $('select[name="cid"]', dom).change(function(event){ self.params.cid = $(this).val(); var url = self.formatParams(self.params); window.location.href = "cekasp_article.htm" + url; }); } formatParams:function(params){ var self = this; var url = ""; for(var param in params){ if(params[param]){ url += param + "=" + params[param] + "&"; } } if(url.length > 0){ url = "?" + url.substring(0,url.length-1); } return url; }
4.后臺(tái)java部分代碼(接收參數(shù),然后過(guò)濾器根據(jù)參數(shù)得到想要的結(jié)果)
String categoryId = request.optString("cid"); if (!ValidateUtil.isNull(categoryId)) { // 加載欄目信息 JSONObject jsonCategory = toJSONObject(adminService.loadById(CekaspCategory.class, categoryId)); response.put("category", jsonCategory); param.addFilter("id", FilterType.IN, articleIdList, 1); } String copyfrom = request.optString("copyfrom"); if (!ValidateUtil.isNull(copyfrom)) { param.addFilter("copyfrom", FilterType.EQUALS, copyfrom); } List<CekaspArticle> articleList = adminService.list(CekaspArticle.class,param);
以上就是使用bootstrap怎么實(shí)現(xiàn)一個(gè)多個(gè)下拉框同時(shí)搜索功能,小編相信有部分知識(shí)點(diǎn)可能是我們?nèi)粘9ぷ鲿?huì)見(jiàn)到或用到的。希望你能通過(guò)這篇文章學(xué)到更多知識(shí)。更多詳情敬請(qǐng)關(guān)注億速云行業(yè)資訊頻道。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。