您好,登錄后才能下訂單哦!
本篇文章為大家展示了利用bootstrap怎么實現一個下拉框搜索功能,內容簡明扼要并且容易理解,絕對能使你眼前一亮,通過這篇文章的詳細介紹希望你能有所收獲。
1、第一個下拉框代碼
<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="搜索數據資源"> <option value="">請選擇數據資源</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="科技動態與進展"> <#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、第二個下拉框代碼
<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、后臺js代碼(url 參數整理)
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、后臺java部分代碼(接收參數,然后過濾器根據參數得到想要的結果)
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怎么實現一個下拉框搜索功能,你們學到知識或技能了嗎?如果還想學到更多技能或者豐富自己的知識儲備,歡迎關注億速云行業資訊頻道。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。