There are several minor problems when using addEventListener() or attachEvent() to bind events in JavaScript:
1. Anonymous functions added using addEventListener() or attachEvent() Cannot be removed.
1 2 3 4 5 6 7 8 |
|
2. In ie6-ie8, the reverse order execution problem of using attachEvent() to bind multiple events.
1 2 3 4 5 6 7 8 9 10 11 12 |
|
Solve the problem
I want to write a cross-browser event binding module so that it can be reused in the future. At the same time, I want to solve the appeal problem. JQuery internally uses event queues and data caching mechanisms to solve this problem. I looked at the relevant source code and found that it is really complicated. I tried some methods myself and managed to achieve it. The code snippet posted was originally written in an object-oriented way. I didn't want it to be complicated, so I changed it to functions.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
|
How to use
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
|
The above is the detailed content of Share an encapsulated javascript event queue function code to solve the problem of binding events. For more information, please follow other related articles on the PHP Chinese website!