怎么使用jQuery实现可输入多选下拉组合框
发表于:2025-11-07 作者:千家信息网编辑
千家信息网最后更新 2025年11月07日,这篇文章主要介绍"怎么使用jQuery实现可输入多选下拉组合框"的相关知识,小编通过实际案例向大家展示操作过程,操作方法简单快捷,实用性强,希望这篇"怎么使用jQuery实现可输入多选下拉组合框"文章
千家信息网最后更新 2025年11月07日怎么使用jQuery实现可输入多选下拉组合框
这篇文章主要介绍"怎么使用jQuery实现可输入多选下拉组合框"的相关知识,小编通过实际案例向大家展示操作过程,操作方法简单快捷,实用性强,希望这篇"怎么使用jQuery实现可输入多选下拉组合框"文章能帮助大家解决问题。
代码如下:
container{ margin: 20px auto; padding:0 15px; width: 50%; height:300px; box-sizing: border-box; } .text-container{ display: inline-block; float:left; width: 15%; height: 32px; line-height: 32px; box-sizing: border-box; } .selectContainer{ width: 70%; height:200px; float:left; position: relative; padding:0; margin:0; box-sizing: border-box; } .selectedContent{ width:85%; height: 25px; float:left; } .dropDown-toggle{ width:14%; height:31px; line-height: 31px; text-align: center; border: 1px solid silver; border-left:none; float:left; padding:0; margin:0; box-sizing: border-box; cursor: pointer; } .dropDown-menu{ margin:0; padding:0 15px 10px; width:100%; border:1px solid silver; border-top: none; box-sizing: border-box; list-style: none; position: absolute; top:31px; right:0; } .items{ margin-top:8px; padding: 2px; cursor: pointer; } .items:hover{ background: #ddd; } .isSelectedText{ display: inline-block; width:90%; } .dsn{ display: none; }最爱的水果选择
$('.isSelected input[type=checkbox]').on('click', function(){ var selectedItems = $(this).parents('.dropDown-menu').prevAll('.selectedContent').val().split(' '); var thisItem = $(this).parent().prev().text(); var isExisted = 0; var isChecked = $(this).is(':checked'); if(isChecked){ selectedItems.map(function(item, index){ if(item === thisItem){ isExisted++ } }); if(!isExisted){ selectedItems.push(thisItem) } } else{ selectedItems.map(function(item, index){ if(item === thisItem){ selectedItems.splice(index, 1); } }); } $(this).parents('.dropDown-menu').prevAll('.selectedContent').val(selectedItems.join(' ')); }) $('.confirmSelect').on('click', function(){ $(this).parents('.dropDown-menu').addClass('dsn'); }) $('.dropDown-toggle').on('click', function(){ $(this).next().toggleClass('dsn') });由于本组件中使用了数组的map方法,可能此方法在ie中不能兼容。由于我电脑ie无法打开,用360浏览器测试后同样可是正常使用。
关于"怎么使用jQuery实现可输入多选下拉组合框"的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识,可以关注行业资讯频道,小编每天都会为大家更新不同的知识点。
下拉
组合
输入
知识
方法
行业
不同
实用
代码
内容
实用性
实际
数组
文章
更多
最爱
案例
橘子
此方法
水果
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
服务器被挂的真实经历
腾讯 云服务器
数据库入门查看建的表的结构
软件开发培训班学历
游咔打不开服务器怎么办
网络安全动态防御能力指标
汕头巡检软件开发
安全数据库和临床数据库
优良苗木繁育数据库
做网络安全小动画
如何避免被软件开发公司制约
中国期刊网全文数据库的检索功能
株洲it软件开发工程师暑假班
网络安全 等有关法律法规
计算机网络技术入门学什么
苹果手机服务器咋改
服务器电子邮件安全
c 和数据库连接
二维码扫描如何连接数据库
常州网络技术有限公司
获取另外一个表的数据库
软件开发做运营
网络安全意识教育的重要性
vba的插入数据库
软件开发成本怎么估算
数据库原理难吗
易华录网络安全与发展研究所
学校软件开发社团面试
网络安全等级设计框架包括
网络安全问题的总结报告