1 <! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
2 3 4 <meta http-equiv= "Content-type" content= "text/html"; Charset=utf-8 "/>
5 <title> Untitled Document </title>
6 <script language= "JavaScript" >
7
8 Var TheP; P Label Object
9
The Var show=function (msg) {//Direct definition function Show (msg) effect is the same
One return function () {
Alert (msg+ "from Show ()");
13
if (window.addeventlistener) {//ff etc.
Thep.removeeventlistener ("Click", Thep.show11, false);
16}
else{//ie
Thep.detachevent ("onclick", THEP.SHOW11);
19}
20}
21}
22
The Var show2=function (msg) {//Direct definition Function show2 (msg) effect is the same
return function () {
Alert (msg+ "from Show2 ()");
26}
27}
28
The function showdef () {
Alert ("Showdef ()");
31
if (window.addeventlistener) {//ff etc.
Thep.removeeventlistener ("Click", Showdef, false);
34}
else{//ie
Thep.detachevent ("onclick", showdef);
37}
38}
39
Window.onload=function () {
Thep=document.getelementbyid ("pid");
42
Thep.show11=show ("Can be detach with parametric method");
44
The IF (Window.addeventlistener)//Not IE
46 {
//for ff.etc
Thep.addeventlistener ("Click", Thep.show11, false);
Thep.addeventlistener ("Click", Showdef, false);
50}
Any else
52 {
//for IE
Thep.attachevent ("onclick", THEP.SHOW11);
Thep.attachevent ("onclick", Show2 (' Can't detach with parameter method '));//difference from previous, here can't detach
56
Thep.attachevent ("onclick", showdef); Methods without parameters write directly
58}
59}
</script>
61
63
<body >
<div >
<p id= "pid" >click me</p>
</div>
</body>
Source: http://www.cnblogs.com/Freeway/archive/2009/06/03/1495561.html