无法在’Window’上执行’getComputedStyle’:参数1不是’Element’类型的错误

我遇到了一些inheritance代码的问题 – 它是一个类似FB的墙上应用程序,注册用户可以发布主题。 很多代码都是JS和jQuery,我对它们知之甚少。

发布主题时,主题会添加到数据库中,但屏幕在刷新之前不显示主题,但应立即显示 – 当我查看开发人员工具时,我收到错误:

Uncaught TypeError: Failed to execute 'getComputedStyle' on 'Window': parameter 1 is not of type 'Element'. 

当我扩展错误时,我得到:

 curCSS @ jquery-1.8.3.js:6825 jQuery.extend.css @ jquery-1.8.3.js:6782 isHidden @ jquery-1.8.3.js:6587 defaultPrefilter @ jquery-1.8.3.js:8797 Animation @ jquery-1.8.3.js:8697 doAnimation @ jquery-1.8.3.js:9034 jQuery.extend.dequeue @ jquery-1.8.3.js:1895 (anonymous function) @ jquery-1.8.3.js:1938 jQuery.extend.each @ jquery-1.8.3.js:611 jQuery.fn.jQuery.each @ jquery-1.8.3.js:241 jQuery.fn.extend.queue @ jquery-1.8.3.js:1931 jQuery.fn.extend.animate @ jquery-1.8.3.js:9044 jQuery.fn.(anonymous function) @ jquery-1.8.3.js:9129 (anonymous function) @ script.js:52 fire @ jquery-1.8.3.js:974 self.fireWith @ jquery-1.8.3.js:1084 done @ jquery-1.8.3.js:7803 callback @ jquery-1.8.3.js:8518 

script.js中的第52行是:

 $('#loadpage').prepend($(response).fadeIn('slow')); 

我希望这不是在jQuery 1.9.x及更高版本中修复的东西,因为升级会破坏太多东西以使其可行但我不知道从哪里开始对此进行故障排除

我发现有三个问题具有相同的错误,但是由于JS知识的问题,我无法从答案中得到任何想法。

取得了一些进展 – 我更新到jQUery 1.9.1,这次发生了同样的事情,但错误发生了变化。 这次错误变成了:

 Uncaught TypeError: Cannot set property 'cur' of undefined 

指向script.js中的同一行

快速搜索在jQuery 1.9中找到了带有fadeIn的Uncaught TypeError ,建议更改该行:

 $('#loadpage').prepend($(response).fadeIn('slow')); 

至:

 $('#loadpage').prepend($(response).show()); 

当我这样做时,不再有任何错误,但它仍然不能正常工作 – 当发布新post时,列表中添加了一个新条目,但它与之前的post重复。 例如,

 Post 1 Post 2 Post 3 

如果我发布一个名为Post 4的新post,则会显示为:

 Post 1 Post 1 Post 2 Post 3 

当我刷新它然后正确显示为Post 4等所以感觉就像一些进步但仍然不完全存在

响应定义如下:

  $('#post').click(function(){ var a = $("#wm").val(); if(a != "") { var keepID = $('#keepID').val(); var posted_on = $('#posted_on').val(); $.post("wall.php?value="+a+'&x='+keepID+'&p='+posted_on, { }, function(response){ //console.log(response); //$('#load').prepend($(response).fadeIn('slow')); $('#load').prepend($(response).show()); $("#wm").val(""); }); } }); 

这个剧本很可怕!

您可能需要在显示之前插入元素。 试试这个:

 $('#post').click(function(){ var a = $("#wm").val(); if(a != "") { var keepID = $('#keepID').val(); var posted_on = $('#posted_on').val(); $.post("wall.php?value="+a+'&x='+keepID+'&p='+posted_on, { }, function(response){ $(response).prependTo($('#load')).fadeIn('slow'); $("#wm").val(""); }); } }); 

如果这不起作用,那么php脚本您传递的GET参数中必定存在错误