使用 jQuery 进行网络聊天
我正在尝试使用 jQuery 实现一个基于浏览器的聊天系统。我想轮询服务器是否有新消息并将它们附加到 div 的底部。我有两个问题。
- 我无法让它将文本附加到 div
- 我不知道如何在附加文本时使 div 滚动到底部
这是我的 HTML 的相关剪辑:
<div id="main">
<form action='post.php' method='post'>
<div id='messages'>stuff</div><br />
<input type='text' name='usertext' />
</form>
</div>
I am trying to implement a browser based chat system with jQuery. I want to poll the server for new messages and append them to the bottom of a div. I have two problems.
- I can't get it to append text to the div
- I don't know how to keep the div scrolled to the bottom as the text gets appended
Here's the relevant clip of my HTML:
<div id="main">
<form action='post.php' method='post'>
<div id='messages'>stuff</div><br />
<input type='text' name='usertext' />
</form>
</div>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不确定你在这里缺少什么。
以及如何滚动到 div 底部
I'm not sure what you're missing here.
And how to scroll to the bottom of a div
使用下面的代码自动滚动到:
Use below code to scrollto automatically: