如何使用Javascript或jQuery在刷新后保持屏幕不变的位置



我有一个页面,用于显示每场比赛的实时分数结果。该页面有两个部分,上部分有实时结果和比赛信息,下部分有评论区。当我发表评论并点击提交页面刷新并转到信息部分时,我想添加评论并刷新页面,然后转到评论的位置(不向上)。我的评论框代码是:

$("#section_bar").after('<textarea rows="4" cols="50"  id="" class="comment_area" name="reply_area" ></textarea><a class="comment button small black" href="#" id="reply_'+match_id+'"><span>submit</span></a>');
$("#reply_"+match_id).live('click',function(){
text_area_value = $('textarea').val();
$.ajax({
type: "POST",
url: 'comment_proxy.php',
data:{id:match_id, user_id:user_id, reply:text_area_value, date:today1, time:time},
dataType: "json",
success: function(data)
{
location.reload();          
},
error : function(XMLHttpRequest, textStatus, errorThrown) {
/*alert(XMLHttpRequest);
alert(textStatus);
alert(errorThrown);
alert(XMLHttpRequest.responseText);*/
}
});
});

我的问题是:是否有任何一行代码可以在location.reload()之后添加,以强制页面提交和刷新,然后保持在提交前的同一点或返回到提交前的相同点????

您不需要重新加载页面location.reload();,也不需要知道数据结果的格式,而是可以从您的帖子中添加结果,如下所示:

使用javascript(因为我不是jQuery开发人员)

success: function(data)
{
// add the "data" to your div
document.getElementById("div_with_posts_id").innerHTML += data;
// maybe clear/reset the form here ?
},

最新更新