我有chatbox每3秒更新一次,并溢出div(chatbody)。我想让evry循环这个函数scroll div bottom?
我的代码
function chat()
{
var xmlhttp;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("chatbody").innerHTML=xmlhttp.responseText;
I THINK CODE MUST BE HERE
}
}
xmlhttp.open("GET","func/chat.php?tnow=" + (new Date()).getTime(),true);
xmlhttp.send();
}
setInterval("chat()",3000);发布于 2012-05-17 15:42:50
function chat()
{
var xmlhttp;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("chatbody").innerHTML=xmlhttp.responseText;
document.getElementById("chatbody").scrollTop = document.getElementById("chatbody").scrollHeight; //This scrolls the chatbox to the bottom/last
}
}
xmlhttp.open("GET","func/chat.php?tnow=" + (new Date()).getTime(),true);
xmlhttp.send();
}
setInterval("chat()",3000);希望这能有所帮助!
https://stackoverflow.com/questions/10631051
复制相似问题