【发布时间】:2014-11-24 20:14:48
【问题描述】:
我的 Laravel 应用中有简单的评论系统。问题是当有人提交评论页面时,页面顶部会重新加载。我希望该页面在原始评论的同一位置返回用户(保持滚动位置)。
这是负责 cmets 的视图的一部分:
@if ($signedIn)
{{ Form::open(['route' => ['comment_path', $status->id], 'class' => 'comments__create-form',]) }}
{{ Form::hidden('status_id', $status->id) }}
<div class="form-group">
{{ Form::textarea('body', null, ['class' => 'form-control', 'rows' => 1]) }}
</div>
{{ Form::close() }}
@endif
@unless ($status->comments->isEmpty())
<div class="comments">
@foreach ($status->comments as $comment)
@include ('statuses.partials.comment')
@endforeach
</div>
@endunless
这是一个 jquery 脚本,当有人点击 ENTER 时提交评论
<script>
$('#flash-overlay-modal').modal();
$('.comments__create-form').on('keydown', function(e) {
if (e.keyCode == 13) {
e.preventDefault();
$(this).submit();
}
});
</script>
感谢您的帮助!
【问题讨论】:
标签: javascript php jquery laravel