Javascript 未能执行';getComputedStyle';在';窗口';:参数1的类型不是';元素';错误
我有一个问题,一些继承的代码-这是一个墙上的应用程序类似FB,注册用户可以张贴主题。很多代码都是JS和jQuery,我对它们都知之甚少 发布主题时,该主题会添加到数据库中,但屏幕在刷新之前不会显示该主题,但它应该立即显示-当我查看开发人员工具时,我会发现错误:Javascript 未能执行';getComputedStyle';在';窗口';:参数1的类型不是';元素';错误,javascript,jquery,Javascript,Jquery,我有一个问题,一些继承的代码-这是一个墙上的应用程序类似FB,注册用户可以张贴主题。很多代码都是JS和jQuery,我对它们都知之甚少 发布主题时,该主题会添加到数据库中,但屏幕在刷新之前不会显示该主题,但它应该立即显示-当我查看开发人员工具时,我会发现错误: Uncaught TypeError: Failed to execute 'getComputedStyle' on 'Window': parameter 1 is not of type 'Element'. 当我展开错误时,我得
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'));
我希望这不是jQuery1.9.x和更高版本中修复的问题,因为升级目前破坏了太多东西,使其可行,但我不知道从哪里开始解决这个问题
我发现三个问题都有相同的错误,但由于缺乏JS知识,我无法从答案中得出任何想法
已经取得了一些进展-我更新到jQUery 1.9.1,这次也发生了同样的情况,但错误发生了变化。这次错误变成:
Uncaught TypeError: Cannot set property 'cur' of undefined
指向script.js中的同一行
快速搜索发现建议更改行:
$('#loadpage').prepend($(response).fadeIn('slow'));
致:
当我这样做时,不再有任何错误,但它仍然不能正常工作-当发布新帖子时,列表中添加了一个新条目,但它与以前的帖子重复。那么比如说,
Post 1
Post 2
Post 3
如果我发布了一个名为post 4的新帖子,那么它将显示为:
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参数中,如果使用,行号会更有用。非常好,我现在将对其进行排序-谢谢您可以在那里设置一个断点并检查
response
的值吗?问题是响应不存在。在你的JQ版本中,这个错误似乎没有被发现。所以问题不在这条线上。我需要更多的上下文。response
具体包含什么?
$('#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("");
});
}
});