这些天在搞GOOGLE MAP,看到GOOGLE的GEvent,很是不错,想着它是怎么实现的,于是自己鼓捣了半天。 <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="test.aspx.cs" Inherits="_3_maps_front.test" %> <!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></title> </head> <body> <form id="form1" runat="server"> <asp:Button ID="Button1" runat="server" Text="Button" /> <div id="test" style="margin-left: auto; margin-right: auto; top: 50px; width: 900px; height: 600px; overflow: hidden; border: solid 1px #000000;"> </div> <div id="ttt"></div> <div id="test2" style="left: 50px; top: 50px; width: 100px; height: 100px; overflow: hidden; border: solid 1px #000000; position: absolute"> </div> <div id="test3" style="left: 50px; top: 150px; width: 100px; height: 100px; overflow: hidden; border: solid 1px #000000; position: absolute"> </div> <mce:script type="text/javascript"><!-- function GEvent() { } GEvent.bindDom = function(DomObj, Event, bindObj, CallBack) { var func; eval("func = function(obj){ obj." + Event + " = function() { CallBack.apply(bindObj, arguments) };}"); func(DomObj); } GEvent.trigger = function(obj, Event) { var func; eval("func = function(obj){ if (obj." + Event + ") obj." + Event + "(); }"); func(obj); } GEvent.addListener = function(obj, Event, CallBack) { var func; eval("func = function(obj){ obj." + Event + " = CallBack; }"); func(obj); } GEvent.removeListener = function(obj, Event) { var func; eval("func = function(obj){ obj." + Event + " = null; }"); func(obj); } function Test() { this.id = "tt"; var div = document.getElementById("test"); var div2 = document.getElementById("test2"); GEvent.bindDom(div, 'onclick', this, function() { GEvent.trigger(this, 'click'); }); GEvent.bindDom(div2, 'onclick', this, function() { GEvent.trigger(this, 'click'); }); GEvent.bindDom(document.getElementById("test3"), 'onclick', this, function() { GEvent.trigger(this, 'click'); }); //GEvent.bindDom(div, 'onmousemove', this, function() { GEvent.trigger(this, 'move'); }); //GEvent.bindDom(div, 'onmouseout', this, function() { GEvent.trigger(this, 'out'); }); } window.onload = function() { var tt = new Test(); GEvent.addListener(tt, 'click', function() { alert("click:这是外部测试"); //GEvent.removeListener(tt, 'click'); }); //GEvent.addListener(tt, 'move', function() { alert("mousemove:这是外部测试"); }); //GEvent.addListener(tt, 'out', function() { alert("mouseout:这是外部测试"); }); } // --></mce:script> </form> </body> </html>