博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
select2删除选中项,allowClear设置
阅读量:4027 次
发布时间:2019-05-24

本文共 495 字,大约阅读时间需要 1 分钟。

在使用select2过程中,有时候需要删除我们选中的选项,如下图:

这时候就需要设置select2的allowClear属性了。

有两种方法:

第一种:

    直接用select2定义的一个class

$(".select2-allow-clear").select2({            allowClear: true,            placeholder: placeholder,            width: null        });

在select标签上加上.select2-allow-clear 的class属性即可;

第二种:

    和上面其实是一样的,自定义选中select标签,自定义属性:

$('#select2Id').select2({         placeholder: "请选择",         placeholderOption: "first",         allowClear: true      });
但是一定要注意,必须添加placeholderOption: "first"属性,否则allowClear不生效

你可能感兴趣的文章
coursesa课程 Python 3 programming 输出每一行句子的第三个单词
查看>>
coursesa课程 Python 3 programming Dictionary methods 字典的方法
查看>>
Returning a value from a function
查看>>
coursesa课程 Python 3 programming Functions can call other functions 函数调用另一个函数
查看>>
coursesa课程 Python 3 programming Tuple Assignment with Unpacking
查看>>
coursesa课程 Python 3 programming The while Statement
查看>>
course_2_assessment_6
查看>>
coursesa课程 Python 3 programming course_2_assessment_7 多参数函数练习题
查看>>
coursesa课程 Python 3 programming 排序函数sorted的可选参数
查看>>
coursesa课程 Python 3 programming course_2_assessment_8 sorted练习题
查看>>
visca接口转RS-232C接口线序
查看>>
在unity中建立最小的shader(Minimal Shader)
查看>>
1.3 Debugging of Shaders (调试着色器)
查看>>
关于phpcms中模块_tag.class.php中的pc_tag()方法的含义
查看>>
vsftp 配置具有匿名登录也有系统用户登录,系统用户有管理权限,匿名只有下载权限。
查看>>
linux安装usb wifi接收器
查看>>
关于共享单车定位不准问题
查看>>
终于搞定CString和string之间转换的问题了
查看>>
用防火墙自动拦截攻击IP
查看>>
补充自动屏蔽攻击ip
查看>>