欢迎访问 生活随笔!

生活随笔

当前位置: 首页 >

select2 手动输入匹配下拉框内容可多选

发布时间:2025/3/19 41 豆豆
生活随笔 收集整理的这篇文章主要介绍了 select2 手动输入匹配下拉框内容可多选 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

这里我选择的是select2这个插件。

官网地址:https://select2.org/getting-started/builds-and-modules

主要实现输入框可以有多选下拉框

<div style="width:100%;height:70px;margin-left: 20px;" id ="multipleDiv"><h2 class="zrl-h"><span style="position:absolute;left: 0;top: 0;width: 100%;text-align: left;font-weight: bold;font-size: 18px;height:2px;">异常数据库</span></h2><br><select id="abnormal_id" multiple="multiple"class="select2" style="width: 85%;"><c:forEach items="${abnormalList}" var="key" ><option value="${key.id}">${key.bigItem}-${key.pettyItem}-${key.expCondition} </option></c:forEach></select><input id="Button" type="button" style="width: 120px;height: 35px;font-size: 20px;font-weight: 600;background: #D9FFFF;border-top-width: 0px;border-left-width: 0px;border-right-width: 0px;border-bottom-width: 0px;margin-left: -20;margin-left: -20;margin-left: -2;" value="确认添加" /> </div> //初始化select$('#abnormal_id').select2({placeholder : '输入体检项目关键字',// tags : true,手动输入字段不在系统内自行添加multiple : true,height: '70px',maximumSelectionLength : 10,allowClear : true,language: "zh-CN",});$("#Button").click(function() {var data = $("#abnormal_id").val();//获取选中值}

我引入的是select2@4.0.12版本 这里tags如果开启会和一些输入法产生冲突导致例如搜狗 会在输入拼音回车后展示出之前输入的拼音和汉字。解决方案是添加以逗号为分割的属性  :  tokenSeparators: [ ',' ],           来解决这个问题

总结

以上是生活随笔为你收集整理的select2 手动输入匹配下拉框内容可多选的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。