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.

二、官网的使用例子:

  1. var $eventLog = $(".js-event-log");
  2. var $eventSelect = $(".js-example-events");
  3. $eventSelect.on("select2:open",function(e){ log("select2:open", e);});
  4. $eventSelect.on("select2:close",function(e){ log("select2:close", e);});
  5. $eventSelect.on("select2:select",function(e){ log("select2:select", e);});
  6. $eventSelect.on("select2:unselect",function(e){ log("select2:unselect", e);});
  7. $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:

val
The current selection (taking into account the result of the change) - id or array of ids.
added
The added element, if any - the full element object, not just the id.
removed
The removed element, if any - the full element object, not just the id.

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:

val
The id of the highlighted choice object.
choice
The highlighted choice object.

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:

val
The id of the highlighted choice object.
choice
The choice object about to be selected.

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:

val
The id of the removing choice object.
choice
The choice object about to be removed.

select2-removed

Fired when a choice is removed or cleared.

The event object contains the following custom properties:

val
The id of the highlighted choice object.
choice
The highlighted choice object.

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:

items
data that was used to populate the results.

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/

jquery插件select2事件不起作用(select2-3.5.4)的更多相关文章

  1. jQuery插件 -- 动态事件绑定插件jquery.livequery.js

    http://blog.csdn.net/zzq58157383/article/details/7721974 动态事件绑定插件livequery, 可以利用它给相应的DOM元素注册事件或者触发回调 ...

  2. jquery插件获取事件类型

    //需要在使用函数时传入event关键字 $('[name=lprice]').change(function(event){ $('[name=lprice]').validate({ event: ...

  3. jquery的return this.each()的作用

    经常看到在运用jquery插件绑定事件时候,都会用到each. 下面来比较下使用return this和return this.each()在使用的区别. 注意:使用each的时候引用this,必须使 ...

  4. jquery.validate.js校验select2解决方案,Jquery插件select2校验解决方案

    jquery.validate.js校验select2解决方案 Jquery插件select2校验解决方案 >>>>>>>>>>>&g ...

  5. html select美化模拟jquery插件select2.js

    代码展示:http://www.51xuediannao.com/demo.php 代码说明: select2.js是一个html select美化模拟类jquery插件,但是select2.js又远 ...

  6. jQuery插件select2跨域设置xhrFields参数

    ajax跨越时默认不带cookie,如果需要带cookie调用,需要设置参数 xhrFields: { withCredentials: true },如: $.ajax({url : "h ...

  7. 详解jquery插件中;(function ( $, window, document, undefined )的作用

    在jquery插件中我们经常看到以下这段代码 1 2 3 ;(function ( $, window, document, undefined ){ //函数体内具体代码 })(jQuery, wi ...

  8. jquery插件中(function ( $, window, document, undefined )的作用

    在jquery插件中我们经常看到以下这段代码 ;(function ( $, window, document, undefined ){ //函数体内具体代码 })(jQuery, window,d ...

  9. 详解jquery插件中(function ( $, window, document, undefined )的作用。

    1.(function(window,undefined){})(window); Q:(function(window,undefined){})(window);中为什么要将window和unde ...

随机推荐

  1. C++构造函数的自动调用(调用一个父类的构造函数,有显性调用最好,否则就默认调用无参数的构造函数)——哲学思想:不调用怎么初始化父类的成员数据和VMT?

    我总是记不住构造函数的特点,关键还是没有领会那个哲学思想:父类的构造函数一方面要初始化它自己的成员数据,另一方面也要建立它自己的VMT呀!心里默念一百遍:一定调用父类构造函数,一定调用父类构造函数,一 ...

  2. String.format 细节

    String.format(Locale.US, format, args); format 参数 如果有% 那么%后面必须跟一个合法的字符,否则崩溃, 因为在String.format中 %为特殊字 ...

  3. 查看本机上的端口使用情况netstat -an

    1.查找本机上的端口使用情况 netstat -an 2.查找指定端口的使用情况 C:\Windows\System32>netstat -ano | find "8002" ...

  4. [LeetCode#281] Zigzag Iterator

    Problem: Given two 1d vectors, implement an iterator to return their elements alternately. For examp ...

  5. C#文本处理(String)学习笔记

    摘要:string是编程中使用最频繁的类型.一个string表示一个恒定不变的字符序列集合.string类型直接继承自object,故他是一个引用类型,也就是说线程的堆栈上不会有任何字符串(直接继承自 ...

  6. POJ_1182_食物链_[NOI]_(并查集)

    描述  http://poj.org/problem?id=1182 共A,B,C三种动物,A吃B,B吃C,C吃A.给出询问 q : t , x , y , 表示: x 与 y 是同类 ( t==1 ...

  7. BZOJ1935: [Shoi2007]Tree 园丁的烦恼

    1935: [Shoi2007]Tree 园丁的烦恼 Time Limit: 15 Sec  Memory Limit: 357 MBSubmit: 552  Solved: 220[Submit][ ...

  8. strcpy,memcpy,内存块重叠

    前段时间准备面试,看了一些库函数的实现,在看到memcpy时,发现有处理source和destination所指内存有重叠的情况,而strcpy没有,特别模仿库函数写了这个函数,并进行了测试.以下是具 ...

  9. bzoj 1493: [NOI2007]项链工厂(线段树)

    1493: [NOI2007]项链工厂 Time Limit: 30 Sec  Memory Limit: 64 MBSubmit: 1256  Solved: 545[Submit][Status] ...

  10. div border-radius

    可以画个1/4之一的圆也可以画整个圆 <html> <style type="text/css"> div{ background-color: #000; ...