为什么这个 div 不会自动滚动?
我已经让它工作得很好,但自动滚动拒绝工作......知道为什么吗?
PS 我只想使用 jQuery...commentsList
位于 commentsPanel
$.ajax({
url: 'comments.php',
type: 'POST',
data: data,
cache: false,
success: function (comments_html) {
$('#commentsPanel').html(comments_html);
var commentsList = document.getElementById('#commentsList');
commentsList.scrollTop = commentsList.scrollHeight;
$('#loading').hide();
}
});
谢谢!
<div id="commentsPanel">
<table width="260" height="220" border="0" cellpadding="3">
<tr><td height="5"></td><td><span style="text-align:right;"><a href="#close" rel="close_comment">Close</tr>
<tr><td height="220" valign="top">
<div id="commentsList" style="overflow: auto; width: 260px; height: 220px; text-align=left">
<!-- CONTENT -->
</div>
</td></tr>
<tr><td height="50">
<form id="new_comment" name="comment_form" method="post" action="comments.php">
<input type="hidden" id="trackID" value="' . $track . '">
<input type="text" size="25" id="new_comment_text" /><span style="text-align:right">
<input type="submit" value="Comment" id="submit_comment"/></span>
</form>
</td></tr>
</table>
</div>
I've got this working nicely, but the autoscroll refuses to work... any idea why?
PS I only want to use jQuery... commentsList
is inside of commentsPanel
$.ajax({
url: 'comments.php',
type: 'POST',
data: data,
cache: false,
success: function (comments_html) {
$('#commentsPanel').html(comments_html);
var commentsList = document.getElementById('#commentsList');
commentsList.scrollTop = commentsList.scrollHeight;
$('#loading').hide();
}
});
Thanks!
<div id="commentsPanel">
<table width="260" height="220" border="0" cellpadding="3">
<tr><td height="5"></td><td><span style="text-align:right;"><a href="#close" rel="close_comment">Close</tr>
<tr><td height="220" valign="top">
<div id="commentsList" style="overflow: auto; width: 260px; height: 220px; text-align=left">
<!-- CONTENT -->
</div>
</td></tr>
<tr><td height="50">
<form id="new_comment" name="comment_form" method="post" action="comments.php">
<input type="hidden" id="trackID" value="' . $track . '">
<input type="text" size="25" id="new_comment_text" /><span style="text-align:right">
<input type="submit" value="Comment" id="submit_comment"/></span>
</form>
</td></tr>
</table>
</div>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
使用
var commentsList = document.getElementById('#commentsList');
时,不需要包含#
When using
var commentsList = document.getElementById('#commentsList');
you dont need to include the#
有趣的是,您说:“我只想使用 jQuery”,但您却使用了 document.getElementById()。
您将 jQuery 与 DOM 方法混淆了。将此行:更改
为:
Funny, you said: "I only want to use jQuery" and yet you use
document.getElementById()
.You're mixing up jQuery with DOM methods. Change this line:
to this:
您说
commentsList
位于commentsPanel
内,但您正在用这一行替换commentsPanel
内的所有内容:您确定吗
commentsList
当时确实存在吗?在var commentsList = ...
行后添加以下内容。以确保它确实存在。
You say that
commentsList
is insidecommentsPanel
but you are replacing everything insidecommentsPanel
with this line:Are you sure that
commentsList
actually exists at the time? Add the following after yourvar commentsList = ...
line.To make sure that it actually exists.