select2搜索框查询加遍历

<div class="form-group">
                    <label class="control-label col-sm-1 no-padding-right" for="entId">公司名称</label>
                    <div class="col-sm-10">
                        <div class="clearfix">
                            <select class="js-example-basic-single js-states form-control" name="entId" id="entId" style="width:100%">
                                <option value="" _level="-1">--请选择--</option>
                                <c:forEach items="${hjPztEntInfoList}" var="item">
                                    <option value="${item.value}">${item.name}</option>
                                </c:forEach>
                            </select>
                        </div>
                    </div>
                </div> 

注意:jquery要在select2的上面
<!-- JQuery script -->
<!-- 非IE浏览器不会识别IE的条件注释,所以这里判断非IE需要如下写法:参照下面jquery-2.1.4.min.js引入的方式 -->
<!--[if !IE]><!-->
<script type="text/javascript" src="${ctx}/resources/js/plugins/jquery/jquery-2.1.4.min.js"></script>
<!--<![endif]-->
<!--[if IE]>
<script type="text/javascript" src="${ctx}/resources/js/plugins/jquery/jquery-1.11.3.min.js"></script>
<![endif]-->
<script type="text/javascript" src="${ctx}/resources/js/plugins/select2/select2.min.js"></script>
<script type="text/javascript" src="${ctx}/resources/js/plugins/select2/zh-CN.js"></script>
<script src="${ctx}/resources/js/pzt/base/hjPztTalentInfo_Detail.js"></script>
这里只有搜索框

$(function(){
    $("#entId").select2({
        templateSelection : function(selection) {
            return $.trim(selection.text);
        }
    });
    validateTalentInfoForm();

})
这里是有加小图标的

$(function(){
    $("#entId").select2({
        //templateResult : formatState,
        templateSelection : function(selection) {
            return $.trim(selection.text);
        }
    });
    validateTalentInfoForm();

})

function formatState(state) {
    var $state = $(‘<span><i class="fa fa-file-text-o green"></i>&nbsp;&nbsp;‘ + state.text + ‘</span>‘);
    return $state;
}
 
时间: 2024-08-04 10:40:13

select2搜索框查询加遍历的相关文章

实现DataTables搜索框查询结果高亮显示

DataTables是封装好的HTML表格插件,丰富了HTML表格的样式,提供了即时搜索.分页等多种表格高级功能.用户可以编写很少的代码(甚至只是使用官方的示例代码),做出一个漂亮的表格以展示数据.关于DataTables的更多信息,请查看:http://www.datatables.club/.https://datatables.net/.下图将要展示的南京景点游记的相关数据,在DataTables表格中展示出来. 上面DataTable表格中的即时搜索.分页等功能是创建好DataTable

在BootStrap的modal中使用Select2搜索框无法输入

用modal来show一个对话框 dialog.modal({ backdrop:true, keyboard:true, show:true }); 1 2 3 4 5 然后再modal中初始化select2 dialog.find("select").select2({ formatNoMatches: function() { return "没有选项"; }, placeholder: "请选择...", minimumResultsFo

Bootstrap 模态框 select2搜索框无法输入

<!--去掉 tabindex="-1" 这个属性--> <!--默认模态框--> <div class="modal fade" id="custom-modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" data-bac

yii2 shi用modal弹窗 select2搜索框无法使用

在modal使用begin的时候指定options选项的tabindex为false Modal::begin([ // ...... 'options' => [ 'tabindex' => false ], ]); 2017-09-30 参考:http://www.manks.top/yii2_modal_gridview_update.html

淘宝购物车页面 智能搜索框Ajax异步加载数据

如果有朋友对本篇文章的一些知识点不了解的话,可以先阅读此篇文章.在这篇文章中,我大概介绍了一下构建淘宝购物车页面需要的基础知识. 这篇文章主要探讨的是智能搜索框Ajax异步加载数据.jQuery的社区非常的活跃,许多朋友都在不同地方分享了很多优秀的插件.我在相关的网站上找过想实现类似功能的插件,但是没有找到.于是乎,自己动手丰衣足食.自己来搭建智能搜索框下拉列表.当然,如果有类似功能并且常维护Bug的插件,望留言交流. 源码地址: 淘宝购物车页面--PC端和移动端项目实战 首先需要先给大家打一根

向DataGrid数据表格增加查询搜索框

向DataGrid数据表格增加查询搜索框 效果如下: js代码: $(function(){ var dg = $('#dg').datagrid({ url:"${pageContext.request.contextPath}/OfferServlet",//servlet路径 columns:[[ {field:'offerid',title:'商品ID',width:100}, {field:'offername',title:'商品名称',width:100}, {field

模糊查询(类似百度搜索框)

很常见的搜索框,很常用,总结一下,怕自己忘了,使用的是原生的js. 这是原生写的,代码很简单,重要是思路.主要就是用了一个indexOf(),很简单.越简单的东西越难想到,很多人都会想到用正则去做,这样就舍近求远了. html部分: <div id="box"> <input type="text" id="txt" value = ""> <input type="button&quo

Select2 在jquery UI Dialog 搜索项失效且不能focus到搜索框解决方案

今天在项目到遇到一个select2插件在jquery UI Dialog 不能focus到搜索框的问题,后来在js 代码中加入(位置可以自己选 ,我选的位置是select2.min.js 后面,因为很多地方都用到,不用针对一个一个功能去修改): $.ui.dialog.prototype._allowInteraction = function(e) {     return !!$(e.target).closest('.ui-dialog, .ui-datepicker, .select2-

Mybatis mysql 一个搜索框多个字段模糊查询 OR

根据搜索框给定的关键词,模糊搜索用户名和账号都匹配的用户集合 <select id="list" parameterType="com.user.UserInfo" resultType="com.user.UserInfo"> SELECT * FROM user WHERE 1 = 1 <if test="searchParam != null and searchParam != ''"> AND