无法在'Window'上执行'getComputedStyle':参数1不是'Element'类型的错误 [英] Failed to execute 'getComputedStyle' on 'Window': parameter 1 is not of type 'Element' error
问题描述
我遇到了一些继承代码的问题 - 它是一个类似FB的墙上应用程序,注册用户可以发布主题。很多代码都是JS和jQuery,我对它们知之甚少。
I am having a problem with some inherited code - it is a wall app something like FB where registered users can post topics. A lot of the code is JS and jQuery and I know little about either.
发布主题时,主题会添加到数据库中,但屏幕不会显示主题直到它被刷新但它应该立即显示 - 当我查看开发人员工具时我得到错误:
When posting a topic the topic gets added to the database but the screen does not show the topic until it is refreshed but it should show immediately - when I look in Developer Tools I get the error:
Uncaught TypeError: Failed to execute 'getComputedStyle' on 'Window': parameter 1 is not of type 'Element'.
当我扩展错误时,我得到:
When I expand the error I get:
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
第52行script.js我s:
Line 52 in script.js is:
$('#loadpage').prepend($(response).fadeIn('slow'));
我希望这不是jQuery 1.9.x及更高版本中修复的东西,因为升级会破坏太多目前的事情是为了让它可行,但我不知道从哪里开始排除故障
I am hoping this isn't something fixed in jQuery 1.9.x and above as upgrading breaks too many things at the moment to make it viable but I have no idea where to begin troubleshooting this
我发现三个问题有相同的错误,但无法得到任何想法从答案可能是由于JS知识的mylack。
I found three questions with the same error but wasn't able to get any ideas from the answers probably due to mylack of JS knowledge.
取得了一些进展 - 我更新到jquery 1.9.1,这次发生了同样的事情,但错误发生了变化。这次错误变成了:
Have made some progress - I updated to jQUery 1.9.1 and this time the same happened but the error changed. This time the error became:
Uncaught TypeError: Cannot set property 'cur' of undefined
指向script.js中的同一行
pointing to the same line in script.js
发现快速搜索 jQuery 1.9中带有fadeIn的未捕获的TypeError 建议更改该行: / p>
A quick search found Uncaught TypeError with fadeIn in jQuery 1.9 which recommended changing the line:
$('#loadpage').prepend($(response).fadeIn('slow'));
to:
$('#loadpage').prepend($(response).show());
当我这样做时,不再有任何错误,但它仍然无法正常工作 - 当发布新帖子有一个新条目添加到列表但它是上一篇文章的副本。例如,
When I do this there are no longer any errors but it still does not quite work correctly - when the new post is posted there is a new entry added to the list but it is a duplicate of the previous post. So for example,
Post 1
Post 2
Post 3
如果我发布一个名为Post 4的新帖子,则显示为:
If I post a new post called Post 4 then it displays as:
Post 1
Post 1
Post 2
Post 3
当我刷新它然后正确显示为Post 4等所以感觉有些进步但仍然不完全
When I refresh it then shows correctly as Post 4 etc so feels like some progress but still not quite there
响应定义如下:
$('#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("");
});
}
});
这个剧本非常可怕!
推荐答案
您可能需要在显示之前插入元素。试试这个:
You'll probably need to insert the element before showing it. Try this:
$('#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参数
这篇关于无法在'Window'上执行'getComputedStyle':参数1不是'Element'类型的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!