Skip to content

Commit 3d2d5ee

Browse files
committed
update
1 parent dec0375 commit 3d2d5ee

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

Example/demo2.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
var Fn = (function(){
2+
var arrachFunctionList = {};
3+
//事件通知
4+
var notify = function (notifyName){
5+
var args = Array.prototype.slice.call(arguments,1);
6+
attachFunctionList[notifyName].fun.apply(attachFunctionList[notifyName].scope,args);
7+
return this;
8+
}
9+
//事件监听
10+
var attach = function(notifyName,callback){
11+
if(typeof notifyName === "string" && typeof callback === "function"){
12+
attachFunctionList[notifyName] = {
13+
fun : callback
14+
};
15+
}
16+
return{
17+
attach:attach,
18+
notify:notify
19+
}
20+
}
21+
}
22+
)();
23+
document.onkeydown = function(e){
24+
var name = "张佳楠";
25+
var number = window.event ? e.keyCode : e.which;
26+
if(number === 9){
27+
//Tab事件后通知该事件已经发生了,并把当前参数传递过去
28+
fn.notify("keydown",name);
29+
}
30+
}
31+
//监听到按钮被点击后进行其他操作
32+
Fn.attach("keydown",function(name){
33+
alert("Tab切换成功!姓名是:" + name)
34+
})

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@
2929
* [04-04](https://github.com/TYRMars/JSlearn#04-04) `DOM结构操作`
3030
* [04-05](https://github.com/TYRMars/JSlearn#04-05) `DOM知识总结`
3131

32-
33-
32+
---
3433

3534
## JS小练习
3635
* JSDemo JS小程序

0 commit comments

Comments
 (0)