0
好的,所以我有一些代码拼凑在一起做出某种聊天室,这是一个黑客工作tbh,但随着我的学习。在这里通过一些答案,但似乎没有任何工作。div不滚动到底部(css,js)
我想要一个JavaScript函数在页面加载时运行。还有另一部分代码在运行时会执行相同的操作(它是在按下按钮时运行的),因此这会让我感到困惑。无论如何。
的CSS:
#result{max-width:1024px; width:100%; padding:10px; background: #0000A0; overflow:auto;}
功能的IM中的index.php的部分努力:
function scrollbottom(){
document.getElementById('result').scrollTop=document.getElementById('result').scrollHeight;
}
我已经打过电话在体内的功能,对负载窗口调用,并在脚本标记内的函数之前和之后调用。
这个代码并运行(也script标签),并执行滚动的div的底部,我没有BTW写这样的代码:
function submitchat(){
if($('#chat').val()=='1' || $('#chatbox').val()==' ') return false;
$.ajax({
url:'chat.php',
data:{chat:$('#chatbox').val(),ajaxsend:true},
method:'post',
success:function(data){
$('#result').html(data); // Get the chat records and add it to result div
document.getElementById('result').scrollTop=document.getElementById('result').scrollHeight; // Bring the scrollbar to bottom of the chat resultbox in case of long chatbox
}
})
return false;
};
和从
<form method="post" onsubmit="return submitchat();">
帮助表示赞赏运行,如果需要,可以发布更多的代码。除CSS文件外,以上所有都在index.php中。
感谢,我想这一点:在window.onload =函数scrollbottom(); function scrollbottom(){ \t document.getElementById('result')。scrollTop = document.getElementById('result')。scrollHeight; }但它不工作,div甚至不显示现在,并且当我使用引用其他函数的按钮页面重新加载,所以不知道那里正在发生什么。 –