我在我的 Laravel 5.1 应用程序中使用 jScroll ( jscroll.com ) 进行无限滚动。我正在进一步使用一些 jquery,我希望在单击每个帖子的“Like”按钮时触发它。Jquery 在第一页的帖子上运行良好,即localhost/myproject/index,但它不会被 jScroll 从下一页(即localhost/myproject/index?page=2等)附加的帖子触发。
这是我显示帖子的代码:
@foreach($posts as $post)
<div class="panel panel-default">
<div class="panel-body post">
<h3>{{ $post->title }}</h3>
<hr>
<p>{{ $post->discripion }}</p>
</div>
<div class="panel-footer">
<div class="btn-group">
<button type="button" data-id="{{$post->id}}" class="btn btn-default like-btn">Like</button>
</div>
</div>
</div>
@endforeach
我想为每个帖子触发的简单 jquery 是:
<script type="text/javascript">
$('button.like-btn').on('click',function(){
var post_id = $(this).data('id');
alert('Liked post with id = ' + post_id);
});
</script>