Skip to content

Commit 6a70e3d

Browse files
committed
提供on事件绑定,多事件名支持
1 parent ba627ac commit 6a70e3d

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

asset/toucher.js

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ window.util.toucher = window.util.toucher || function (dom){
3333
* @param [function] 符合条件的事件被触发时需要执行的回调函数
3434
*
3535
*/
36-
function ON(eventName,a,b){
36+
function ON(eventStr,a,b){
3737
this._events = this._events || {};
3838
var className,fn;
3939
if(typeof(a) == 'string'){
@@ -43,16 +43,20 @@ window.util.toucher = window.util.toucher || function (dom){
4343
className = null;
4444
fn = a;
4545
}
46-
//事件名存在且callback合法,进行监听绑定
47-
if(eventName.length > 0 && typeof(fn) == 'function'){
48-
//事件堆无该事件,创建一个事件堆
49-
if(!this._events[eventName]){
50-
this._events[eventName] = [];
46+
//检测callback是否合法,事件名参数是否存在·
47+
if(typeof(fn) == 'function' && eventStr && eventStr.length){
48+
var eventNames = eventStr.split(/\s+/);
49+
for(var i=0,total=eventNames;i<total;i++){
50+
var eventName = eventNames[i];
51+
//事件堆无该事件,创建一个事件堆
52+
if(!this._events[eventName]){
53+
this._events[eventName] = [];
54+
}
55+
this._events[eventName].push({
56+
'className' : className,
57+
'fn' : fn
58+
});
5159
}
52-
this._events[eventName].push({
53-
'className' : className,
54-
'fn' : fn
55-
});
5660
}
5761

5862
//提供链式调用的支持

0 commit comments

Comments
 (0)