[英]DIV Scroll down to bottom Script Error JQUERY
我收到此函数的错误
function scrolldown() {
$("#chatArea").scrollTop($("#chatArea")[0].scrollHeight);
}
Fehler:TypeError:$(...)[0]未定义
在ajax查询中调用此脚本以更新聊天框以滚动到底部
function refreshChat()
{
$.ajax({
type: "POST",
url: "ajax/sb.php",
success: function(msg){
$("#chatArea").html(msg);
scrolldown();
}
});
}
每5秒更新一次
window.setInterval("refreshChat()",5000);
有什么建议么?
我相信这应该有用
function scrolldown() {
$("#chatArea").scrollTop(document.getElementById('chatArea').scrollHeight);
}
消除使用$("#chatArea")[0]
将返回带有jQuery的dom元素的事实。 但是无论出于何种原因,它似乎都将返回错误。
编辑
我的答案已解决原始问题,但您已更新:
TypeError: document.getElementById(...) is null
这基本上意味着找不到该元素。 简而言之,函数运行时$("#chatArea")
不在DOM中。 它不存在。 运行该函数时,请确保$("#chatArea")
可用。
尝试这个
function scrolldown() {
$("#chatArea").scrollTop($("#chatArea").get(0).scrollHeight);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.