jquery插件select2事件不起作用(select2-3.5.4)
jquery插件select2事件不起作用
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
蕃薯耀 2015年10月8日 09:01:53 星期四
http://fanshuyao.iteye.com/
一、官网的说明:https://select2.github.io/examples.html(Version 4.0.0)
change
is fired whenever an option is selected or removed.
select2:open
is fired whenever the dropdown is opened. select2:opening
is fired before this and can be prevented.
select2:close
is fired whenever the dropdown is closed. select2:closing
is fired before this and can be prevented.
select2:select
is fired whenever a result is selected. select2:selecting
is fired before this and can be prevented.
select2:unselect
is fired whenever a result is unselected. select2:unselecting
is fired before this and can be prevented.
二、官网的使用例子:
- var $eventLog = $(".js-event-log");
- var $eventSelect = $(".js-example-events");
- $eventSelect.on("select2:open",function(e){ log("select2:open", e);});
- $eventSelect.on("select2:close",function(e){ log("select2:close", e);});
- $eventSelect.on("select2:select",function(e){ log("select2:select", e);});
- $eventSelect.on("select2:unselect",function(e){ log("select2:unselect", e);});
- $eventSelect.on("change",function(e){ log("change");});
但是在实际应用中select2:close不起作用。
三、解决方法:
这个原因找了很久都没有找到,昨天终于发现原因了:
$("#xxx").on("select2-close", function (e) { });
原来是select2-close,中间的不是冒号,而是 - (横杠),修改后就能使用了
jquery.validate.js插件也能完善校验。
$("#genders").on("select2-close", function (e) {
$(this).valid();
});
最终原因是select2的版本问题
在3.5.4版本中的事件为:
Events
change
Fired when selection is changed.
The event object contains the following custom properties:
select2-opening
Fired before the dropdown is shown.
The event listener can prevent the opening by calling preventDefault()
on the supplied event object.
select2-open
Fired after the dropdown is shown.
select2-close
Fired after the dropdown is closed.
select2-highlight
Fired when a choice is highlighted in the dropdown.
The event object contains the following custom properties:
select2-selecting
Fired when a choice is being selected in the dropdown, but before any modification has been made to the selection. This event is used to allow the user to reject selection by calling event.preventDefault()
The event object contains the following custom properties:
select2-clearing
Fired when a choice is being cleared in the dropdown, but before any modification has been made to the selection. This event is used to allow the user to reject the clear by calling event.preventDefault()
For the clear button to be visible the allowClear
option needs to be true
.
select2-removing
Fired when a choice is about to be removed in the dropdown/input, but before any removal of the choice has been made. This event is used to allow the user to reject removal by calling event.preventDefault()
The event object contains the following custom properties:
select2-removed
Fired when a choice is removed or cleared.
The event object contains the following custom properties:
select2-loaded
Fired when query function is done loading the data and the results list has been updated
The event object contains the following custom properties:
select2-focus
Fired when the control is focussed.
select2-blur
Fired when the control is blurred.
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
蕃薯耀 2015年10月8日 09:01:53 星期四
http://fanshuyao.iteye.com/
最新文章
- 百度地图 获取两点坐标之间的驾车距离(非直线距离) c#
- POJ 1321 DFS
- java中的反射,知道类名创建类,还可以设置私有属性的值
- 在bootstrap ace样式框架上修改的后台管理型模板(Tab页后台管理模板)
- ID
- [IIS] eset/Restart/Recycling/Refresh 的区别
- jqgrid 列显示图片
- 使用了非标准扩展:“xxx”使用 SEH,并且“xxx”有析构函数
- [转载]汇编eax寄存器和AX,AH,AL之间的关系
- gentoo下的wpa_supplicant无线网配置
- 搜索框中“请输入搜索keyword”
- 浏览器兼容性判定写法格式(ie)
- lastcomm搜索并显示以前执行过的命令信息
- Linux下安装memcached
- 【.Net Framework 体积大?】不安装.net framework 也能运行!?开篇叙述-1
- RBAC权限管理系统
- Oracle系统表外键的更名
- DL中train\dev\test集
- Arrays 类的 binarySearch() 数组查询方法详解
- Javascript Iterator
热门文章
- Android软件开发之获取通讯录联系人信息
- jap中文转码
- 3.android下Makefile编写规范
- Json遇到引号需要转义的问题
- [pod install] error: cannot open .git/FETCH_HEAD: Permission denied
- Unity3D游戏开发入门(一)
- webstorage调查资料汇总
- 为什么 UDP 有时比 TCP 更有优势
- __attribute__机制介绍 (转)
- KMP算法(模板)