<div id='floater' style='z-index: 1000; left: 2px; position: absolute; width: 200px;
        height: 126px; top: 43px;'>
        <img id="" src='/images/peixunbu/peixu35.jpg' style="cursor: pointer; width: 200px;
            height: 126px;" alt="第四届海峡两岸平板显示产业合作论坛" />
    </div>    <script type="text/javascript">
        var floaterBanner = function(step, delay, floaterid, url) {
            this.step = step;
            this.delay = delay;
            this.yon = 0;
            this.xon = 0;
            this.interval = null;
            this.floater = document.getElementById(floaterid);
            this.xPos = 0;
            this.yPos = 0;
            this.url = url;            this.start();
        }
        floaterBanner.prototype = {
            changePos: function() {
                var de = document.documentElement;
                var width = de.clientWidth;
                var height = de.clientHeight;
                var Hoffset = this.floater.offsetHeight;
                var Woffset = this.floater.offsetWidth;
                this.floater.style.left = this.xPos + de.scrollLeft;
                this.floater.style.top = this.yPos + de.scrollTop;
                var left = parseInt(this.floater.style.left);
                var top = parseInt(this.floater.style.top);                if ((left + Woffset) == (de.clientWidth + de.scrollLeft)) {
                    this.xon = 1;
                }
                else if (left <= 0) {
                    this.xon = 0;
                }
                this.floater.style.left = (this.xon == 1) ? (this.xPos - this.step + de.scrollLeft) : (this.xPos + this.step + de.scrollLeft);
                this.xPos = (this.xon == 0) ? (this.xPos + this.step) : (this.xPos - this.step);                if ((top + Hoffset) == (de.clientHeight + de.scrollTop)) {
                    this.yon = 1;
                }
                else if (top <= 0) {
                    this.yon = 0;
                }
                this.floater.style.top = (this.yon == 1) ? (this.yPos - this.step + de.scrollTop) : (this.yPos + this.step + de.scrollTop);
                this.yPos = (this.yon == 0) ? (this.yPos + this.step) : (this.yPos - this.step);
            },            start: function() {
                var o = this;
                o.floater.onmouseover = function() {
                    if (o) {
                        clearInterval(o.interval);
                    }
                }
                o.floater.onmouseout = function() {
                    if (o) {
                        o.interval = setInterval(function() { o.changePos() }, o.delay);
                    }
                }
                o.floater.onclick = function() {
                    if (o) {
                        window.open(o.url);
                        o.floater.style.display = "none";
                        clearInterval(o.interval);
                        o = null;
                    }
                }
                o.floater.visibility = "visible";
                o.interval = setInterval(function() { o.changePos() }, o.delay);            },
        }
        var floater123582 = new floaterBanner(1, 5, "floater", "http://www.fpdisplay.com/xm2010");    </script>我想点击浮动的对象之后,将该浮动对象清除掉。。
o.floater.onclick = function() {
                    if (o) {
                        window.open(o.url);
                        o.floater.style.display = "none";
                        clearInterval(o.interval);
                        o = null;
                    }
                }
但是 我发现并没有清除掉

解决方案 »

  1.   

    为 floaterBanner 写一个dispose()方法,在方法内用 document.removeChild方法将那个div 删除掉.
    你这样试试吧.
      

  2.   


     function tt() {
                alert(floater123582.url);
            }
    这个对象所有东西都存在。。
    怎样写disposed()?
    将div删除掉会怎样?
    div我可以让他存在。。但是floater123582这家伙 就不想要啦
      

  3.   

    根据对象回收的原则 只要一个对象还被引用 则不会被回收
    var o=this ;
    则 o是 this的别名 因此 o=null  不代表 this=null
      

  4.   

    根据对象回收的原则 只要一个对象还被引用 则不会被回收 
    var o=this ; 
    则 o是 this的别名 因此 o=null  不代表 this=null 的确是这样。
    那么我想把 this 回收呢?
      

  5.   

    没有那个必要
    ,你上面的代码中this无法回收,、
    实在想回收
    var ff=new floaterBanner();
    ff=null//这样应该就可以了吧
      

  6.   

    个人感觉确实没有必要.如果是dom对象,那你需要obj.parentNode.removeChild(obj)
    否则直接赋null值就可以了啊.obj=null;
      

  7.   

    我也知道是null
    只是在对象里面
      o.floater.onclick = function() {
                        if (o) {
                            window.open(o.url);
                            o.floater.style.display = "none";
                            clearInterval(o.interval);
                            o = null;
                        }
                    }
    执行完 这个之后怎样回收?
      

  8.   

    回收的对象先列出来
    然后所有对这个对象的引用全设置null
    引用一般就是变量按你上面哪个对象
    其中又关联了页面的DOM 那应该回收不掉 除非你把这个关联去掉
      

  9.   

    不清楚你的回收是释放内存呢,还是删除掉页面中的某一个dom对象...
      

  10.   

    回收的对象先列出来 
    然后所有对这个对象的引用全设置null 
    引用一般就是变量 按你上面哪个对象 
    其中又关联了页面的DOM 那应该回收不掉 除非你把这个关联去掉 
    呵呵我明白啦。。
    是可以循环设置该对象所有属性 为null
    目的是释放内存
      

  11.   

    接赋null值就可以了啊.obj=null!!!!!
      

  12.   

    接赋null值就可以了啊.obj=null!!!!!
    我也知道直接 .obj=null 
    但是在对象里面怎样 .obj=null 呢?js不熟悉啊
    你看下面这个函数:应该怎样做。。
    o 是当前 对象
    o.floater.onclick = function() { 
            var  o = this;
                        if (o) { 
                            window.open(o.url); 
                            o.floater.style.display = "none"; 
                            clearInterval(o.interval); 
                            o = null; 
                        } 
                    }