<! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<HTML xmlns = "http://www.w3.org/1999/xhtml">
<Head runat = "server">
<Title> untitled page </title>
</Head>
<Body>
<Form ID = "form1" runat = "server">
<Div>
<A href = "#" id = "link1" AAA = "A"> test link </a>
<Input type = "button" value = "attachevent" onclick = "addevent ();"/>
</Div>
</Form>
<Input type = "text" id = "msg" value = "111"/>
</Body>
</Html>
<Script type = "text/javascript">
Function bind (obj, type, fn, argsObject ){
Var eventHandler = fn;
If (argsObject ){
EventHandler = function (e ){
Fn. call (argsObject, e );
};
}
If (window. attachEvent) {// IE
Obj. attachEvent ("on" + type, eventHandler );
} Else {// FF
Obj. addEventListener (type, eventHandler, false );
}
};
Function unBind (obj, type, fn ){
If (obj. attachEvent ){
Obj ['E' + type + fn] = fn;
Obj [type + fn] = function () {obj ['E' + type + fn] (window. event );};
Obj. detachEvent ("on" + type, fn );
} Else {
Obj. removeEventListener (type, fn );
};
};
Function linkClick (e ){
/* This: The last parameter e.tar get when bind is used: the object that triggers the event */
This. value = "333 ";
Var target = e. srcElement | e.tar get;
Alert (target. getAttribute ('aaa '));
}
Function addEvent (){
Var msg = document. getElementById ("msg ");
Var link1 = document. getElementById ("link1 ");
Bind (link1, "click", linkClick, msg );
}
</Script>