jquery input事件
生活随笔
收集整理的這篇文章主要介紹了
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
轉載于:https://www.cnblogs.com/yc-code/p/5089002.html
總結
以上是生活随笔為你收集整理的jquery input事件的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Android HttpURLConne
- 下一篇: JSTL(JSP Standard Ta