Lonsan
博客园
首页
社区
新文章
新随笔
订阅
管理
posts - 4, comments - 17, trackbacks - 0
2005年4月9日
HTML中利用堆栈方式对Table进行行排序
posted @ 2005-04-09 12:34 蓝山 阅读(1249) 评论(1)
编辑
2005年4月8日
JS类中event的简单实现(续)
<!--
description:JS类中event的简单实现2
code by Lonsan on 2005
email:Lonsan21@163.com
请各位多批评指导,谢谢
-->
<
html
>
<
head
>
<
title
>
JS Event2
</
title
>
<
style
>
</
style
>
</
head
>
<
body
>
</
body
>
</
html
>
<
script
language
="javascript"
>
<!--
//
实现,实现类似C#风格调用
//
已经支持+=和-=操作符,但是还存在很多问题,正寻求解决方法
//
注:参考了birdshome提示,在此表示感谢。
function
RaiseEvent(sender,event)
{
var
funs
=
""
;
for
(
var
k
in
EventHandler.Events)
{
if
(k
==
"
length
"
)
continue
;
if
((event
&
EventHandler.Events[k].ID)
>
0
)
{
funs
+=
k
+
"
(sender);\n
"
;
}
}
eval(
"
var f = function(sender){\n
"
+
funs
+
"
\n}
"
);
f(sender);
}
function
EventHandler(o)
{
this
.EventID;
var
fname;
if
(
typeof
o
==
"
function
"
)
{
fname
=
o.toString().match(
/
function
([
^
\
0
\(]
*
)\(
/
)[
1
];
if
(EventHandler.Events[fname]
==
null
)
{
this
.EventID
=
(
1
<<
EventHandler.Events.length);
EventHandler.Events[fname]
=
{ID:
this
.EventID}
;
EventHandler.Events.length
++
;
}
else
{
this
.EventID
=
EventHandler.Events[fname].ID;
}
}
}
EventHandler.Events
=
{length:
0
}
;
EventHandler.Null
=
0
;
EventHandler.prototype.toString
=
function
()
{
return
this
.EventID;
}
//
////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
示例
function
Persion()
{}
Persion.prototype.onBeginSpeak
=
EventHandler.Null;
Persion.prototype.name
=
"
Lonsan
"
;
Persion.prototype.Speak
=
function
(sWords)
{
RaiseEvent(
this
,
this
.onBeginSpeak);
alert(
"
正在讲话。。。\n以下是讲话内容:\n
"
+
sWords);
}
var
p
=
new
Persion()
//
test1
p.onBeginSpeak
+=
new
EventHandler(BeginSpeak1);
p.onBeginSpeak
+=
new
EventHandler(BeginSpeak2);
alert(
"
测试1开始!!
"
);
p.Speak(
"
大家好,我是
"
+
p.name
+
"
。
"
);
//
test2
p.onBeginSpeak
-=
new
EventHandler(BeginSpeak2);
p.onBeginSpeak
+=
new
EventHandler(BeginSpeak3);
alert(
"
测试2开始!!
"
);
p.Speak(
"
第二次\n已经取消BeginSpeak2事件。\n我是
"
+
p.name
+
"
。
"
);
function
BeginSpeak1(sender)
{
alert(
"
处理BeginSpeak事件!--1\n
"
);
}
function
BeginSpeak2(sender)
{
alert(
"
处理BeginSpeak事件!--2
"
);
}
function
BeginSpeak3(sender)
{
sender.name
=
"
(Lonsan)蓝山
"
;
alert(
"
处理BeginSpeak事件!--3
"
);
}
//
-->
</
script
>
posted @ 2005-04-08 13:11 蓝山 阅读(944) 评论(5)
编辑
2005年4月7日
JS类中event的简单实现
摘要: js 事件模拟
阅读全文
posted @ 2005-04-07 17:45 蓝山 阅读(1666) 评论(9)
编辑
2004年7月23日
开张了
开张庆贺!
posted @ 2004-07-23 09:59 蓝山 阅读(600) 评论(2)
编辑
仅列出标题
昵称:
蓝山
园龄:
7年6个月
粉丝:
0
关注:
0
<
2012年2月
>
日
一
二
三
四
五
六
29
30
31
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
1
2
3
4
5
6
7
8
9
10
搜索
常用链接
我的随笔
我的评论
我的参与
最新评论
我的标签
随笔档案
2005年4月 (3)
2004年7月 (1)
最新评论