prototype
直接贴解释了
使用原型来创建对象
在编写构造函数时,可以使用原型对象(它本身是所有构造函数的一个属性)的属性来创建继承属性和共享方法。原型属性和方法将按引用复制给类中的每个对象,因此它们都具有相同的值。可以在一个对象中更改原型属性的值,新的值将覆盖默认值,但仅在该实例中有效。属于这个类的其他对象不受此更改的影响。

解决方案 »

  1.   

    好象没说清楚
    事件在第一个div上  双击  结果把第2个div关闭了
    代码重新贴一下
    <style type="text/css">
    .ff{ width:300px; height:200px; background:#990000; margin:20px;}
    </style>
    <script>
    function haha(a){
    this.parent = document.body
    this.id=a
    }haha.prototype.create=function(){
    var div = document.createElement("div")
    div.className = "ff"
    div.id=this.id
    this.parent.appendChild(div)
    this.db()
    }haha.prototype.db=function(){
    var obj = document.getElementById(this.id)
    var me = this
    obj.attachEvent("ondblclick",function(){ me.remove()})
    }haha.prototype.remove = function(){
    document.body.removeChild(document.getElementById(this.id))
    }window.onload= function (){
    var g = new haha("a")
    g.create()
    var c = new haha("b")
    c.create()
    }
    </script>
    <body>
    </body>
      

  2.   

    用的同一个ID吧<style type="text/css">
    .ff{ width:300px; height:200px; background:#990000; margin:20px; color:#fff; font:bold 30px/200px '宋体'; text-align:center;}
    </style>
    <script>
    function haha(a){
    this.parent = document.body
    this.id=a
    }haha.prototype.create=function(){
    var div = document.createElement("div")
    div.className = "ff";
    div.innerHTML = this.id;
    div.id=this.id
    this.parent.appendChild(div)
    this.db()
    }haha.prototype.db=function(){
    var obj = document.getElementById(this.id)
    var me = this
    obj.attachEvent("ondblclick",function(){ me.remove()})
    }haha.prototype.remove = function(){
    document.body.removeChild(document.getElementById(this.id))
    }window.onload= function (){
    var g = new haha('a')
    g.create()
    var c = new haha('b')
    c.create()
    }
    </script>
    <body>
    </body>
      

  3.   

    不是id的问题吧
    后面用的是不同的id了
    点第一个div还是先关闭的第2个div
    其实对这些机制很不熟悉
      

  4.   

    在ie7下没有发现你所说的那个问题
    <style type="text/css">
    .ff{ width:300px; height:200px; background:#990000; margin:20px;}
    </style>
    <script>
    function haha(a){
    this.parent = document.body
    this.id=a
    }haha.prototype.create=function(){
    var div = document.createElement("div")
    div.innerHTML="<font color=white>"+this.id+"</font>";
    div.className = "ff"
    div.id=this.id
    this.parent.appendChild(div)
    this.db()
    }haha.prototype.db=function(){
    var obj = document.getElementById(this.id)
    var me = this
    obj.attachEvent("ondblclick",function(){ me.remove()})
    }haha.prototype.remove = function(){
    document.body.removeChild(document.getElementById(this.id))
    }window.onload= function (){
    var g = new haha("a")
    g.create()
    var c = new haha("b")
    c.create()
    }
    </script>
    <body>
    </body>
      

  5.   

    ie6
    点第1个div
    结果第2个div先关闭了。。
      

  6.   

    <style type="text/css">
    .ff{ width:300px; height:200px; background:#990000; margin:20px;}
    </style>
    <script>
    function haha(a){
    this.parent = document.body
    this.id=a
    }haha.prototype.create=function(){
    var div = document.createElement("div")
    div.className = "ff"
    div.id=this.id
    div.innerHTML=div.id;
    this.parent.appendChild(div)
    this.db()
    }haha.prototype.db=function(){
    var obj = document.getElementById(this.id)
    var me = this
    obj.attachEvent("ondblclick",function(){ me.remove()})
    }haha.prototype.remove = function(){
    document.body.removeChild(document.getElementById(this.id))
    }window.onload= function (){
    var g = new haha("a")
    g.create()
    var c = new haha("b")
    c.create()
    }
    </script>lz点第一个消失后第二个顶上去了
    并不是第二个关闭了
      

  7.   

    你的错觉吧
    我改了下<style type="text/css">
    .ff{ width:300px; height:200px; background:#990000; margin:20px;}
    </style>
    <script>
    function haha(a){
    this.parent = document.body
    this.id=a
    }haha.prototype.create=function(){
    var div = document.createElement("div")
    div.className = "ff"
    div.innerHTML = this.id//看看关的是那个
    div.id=this.id
    this.parent.appendChild(div)
    this.db(div)
    }haha.prototype.db=function(obj){
    var me = this
    obj.attachEvent("ondblclick",function(){ me.remove(obj)})
    }haha.prototype.remove = function(obj){
    document.body.removeChild(obj)
    }window.onload= function (){
    var g = new haha('a')
    g.create()
    var c = new haha('b')
    c.create()
    }
    </script>
    <body>
    </body>
      

  8.   

    嘿嘿
    果然是下面的一个div顶上去了