File tree Expand file tree Collapse file tree 2 files changed +35
-2
lines changed
Expand file tree Collapse file tree 2 files changed +35
-2
lines changed Original file line number Diff line number Diff line change 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+ } )
Original file line number Diff line number Diff line change 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小程序
You can’t perform that action at this time.
0 commit comments