jquery input事件

 1 /* 
 2 * jQuery input event 
 3 * Author: tangbin 
 4 * Blog: http://www.planeart.cn 
 5 * Date: 2011-08-18 15:15 
 6 */
 7 (function ($) {
 8 
 9     // IE6\7\8不支持input事件,但支持propertychange事件  
10     if ('onpropertychange' in document) {
11         // 检查是否为可输入元素  
12         var rinput = /^INPUT|TEXTAREA$/,
13                 isInput = function (elem) {
14                     return rinput.test(elem.nodeName);
15                 };
16 
17         $.event.special.input = {
18             setup: function () {
19                 var elem = this;
20                 if (!isInput(elem)) return false;
21 
22                 $.data(elem, '@oldValue', elem.value);
23                 $.event.add(elem, 'propertychange', function (event) {
24                     // 元素属性任何变化都会触发propertychange事件  
25                     // 需要屏蔽掉非value的改变,以便接近标准的onput事件  
26                     if ($.data(this, '@oldValue') !== this.value) {
27                         $.event.trigger('input', null, this);
28                     };
29                     $.data(this, '@oldValue', this.value);
30                 });
31             },
32             teardown: function () {
33                 var elem = this;
34                 if (!isInput(elem)) return false;
35                 $.event.remove(elem, 'propertychange');
36                 $.removeData(elem, '@oldValue');
37             }
38         };
39     };
40 
41     // 声明快捷方式:$(elem).input(function () {});  
42     $.fn.input = function (callback) {
43         return this.bind('input', callback);
44     };
45 
46 })(jQuery);

http://blog.csdn.net/huangxy10/article/details/40455121

posted on 2015-12-30 15:37  流浪小白鼠  阅读(1467)  评论(0编辑  收藏  举报