IE:'nodeType'为null或不是对象

ane*_*yzm 6 jquery internet-explorer

我在IE(6,7,8)的网站上遇到了这个问题:

'nodeType'为null或不是对象

该错误引用"f.nodeType"属性.基本上f是未定义的,所以问题出在之前,但我无法解决它.

(从IE开发人员工具栏调试它似乎是抛出错误的这一行)(autocolumn.min.js line 13为了便于阅读,扩展如下)

页面位于http://www.donatellabernardi.ch/drupal

function split($putInHere,$pullOutHere,$parentColumn,height){
  if($pullOutHere.children().length){
    $cloneMe=$pullOutHere.children(":first");
    $clone=$cloneMe.clone(true);
    if($clone.attr("nodeType")==1&&!$clone.hasClass("dontend")){
    ^^^^^^^^^^^^^^^^^^^^^^^^^^ Chokes on

      $putInHere.append($clone);
      if($clone.is("img")&&$parentColumn.height()<height+20){
        $cloneMe.remove();
      }else if(!$cloneMe.hasClass("dontsplit")&&$parentColumn.height()<height+20){
        $cloneMe.remove();
      }else if($clone.is("img")||$cloneMe.hasClass("dontsplit")){
        $clone.remove();
      }else{
        $clone.empty();
        if(!columnize($clone,$cloneMe,$parentColumn,height)){
          if($cloneMe.children().length){
            split($clone,$cloneMe,$parentColumn,height);
          }
        }
        if($clone.get(0).childNodes.length==0){
          $clone.remove();
        }
      }
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

Cod*_*kie 4

使用“Firebug lite”书签(您可以在此处获取它: http: //getfirebug.com/firebuglite),我可以缩小实际引发错误的位置。

看来问题的根源不在于您提取的代码,而在于 jQuery 本身。

我注意到您使用的是 jQuery 版本 1.2.6。问题是该版本的克隆方法。这会导致您发布的代码行中出现错误:

$clone=$cloneMe.clone(true);
Run Code Online (Sandbox Code Playgroud)

我可以为您提供更多详细信息,说明错误发生的具体位置,但我认为这不会解决您的问题。无论如何,为有缺陷的 jQuery 代码构建解决方法并不是一个好主意。我宁愿建议尝试更新版本的 jQuery(快速浏览后我发现克隆方法的实现方式不同),看看是否可以解决您的问题。

编辑: 抱歉,这不是这一行

$clone=$cloneMe.clone(true);
Run Code Online (Sandbox Code Playgroud)

但这行:

$cache.append($(this).children().clone(true));
Run Code Online (Sandbox Code Playgroud)

(autocolumn.js 中的第 42 行)