面向对象HTIS
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head> <title>new document</title> <script type="text/javascript"> function activeDiv(){ var div = document.createElement("div"), self = this; div.style.cssText = "position:absolute; width:300px; height:200px; left:100px;top:100px; border:1px solid #006699; background:#f5f6fb;"; div.onclick = function(){ self.drag(); }; this.element = div; } activeDiv.prototype.drag = function(){ alert("drag"); }; window.onload = function(){ var drag = new activeDiv(); document.body.appendChild(drag.element); }; </script> </head> <body> </body> </html>