+ -
当前位置:首页 → 问答吧 → 为什么这个node是null?

为什么这个node是null?

时间:2011-10-11

来源:互联网

写了一个js函数,遍历当前页面,并给页面中的所有元素增加onmouseover listener,然后希望能在鼠标指向它的时候,弹出个窗口告诉我这个元素的tag,但是node(红色)不知道为什么是Null,求助啊!

JScript code

 run : function () {    

            var iterator = document.createNodeIterator(content.document, NodeFilter.SHOW_ELEMENT, null, false);
            var node1 = iterator.nextNode();
            if (node1 != null) {
              node1.addEventListener('mouseover', function () {add(node1)}, false);
            }

            while (node1) {
              node1 = iterator.nextNode();
              if (node1 != null) {
                node1.addEventListener('mouseover', function () {add(node1)}, false);
              }
            }    
      
            function add(node) {[color=#FF0000]这里为什么node是null啊,换成node1也不行[/color]
              alert(node.tagName + " has been moved over");
            }
}

作者: genius1wjc   发布时间: 2011-10-11

你给NODE 传值了吗?

作者: zsx841021   发布时间: 2011-10-11

调试一下。。。看有没有给NODE 传进来值

作者: zsx841021   发布时间: 2011-10-11

node1.addEventListener('mouseover', function () {add(node1)}, false);
这句话传进去了吧?

作者: genius1wjc   发布时间: 2011-10-11

我这段代码写在FF插件里面了,怎么调试?

作者: genius1wjc   发布时间: 2011-10-11