自动点击加载更多但仅在第一次手动点击

时间:2017-08-22 05:03:59

标签: javascript php jquery

我尝试添加自动点击加载更多链接,但自动加载更多仅在手动点击后触发。我坚持这个。如果有人知道解决方案,请帮助。

 <?php if( $next_link !== false ):?>
        <div class="sp-load-more text-center"  >
         <a href='#'  title="Load more result" data-url="<?php echo $next_link;?>" onclick="return doko.BuSfw16AlL(this, {container: '#search-results', rc : '.sp-load-more'})">
            <span id="l-more" > Load More <i  class="fa fa-angle-down fa-lg"></i>  </span>
          </a>
            </div>

<?php else:?>
        <div class="panel sp-box sp-load-more">
                <div class="panel-body">
                <span>-- End of Result --</span> 
                </div>
        </div>
<?php endif; ?>

<script >
$(function(){ //on document ready
    $(document).scroll(function (e) { //bind scroll event

        var intBottomMargin = 300; //Pixels from bottom when script should trigger

        //if less than intBottomMargin px from bottom
        if ($(window).scrollTop() >= $(document).height() - $(window).height() - intBottomMargin) {
            $("#l-more").click(); //trigger click
        }

    });
});
</script>

1 个答案:

答案 0 :(得分:0)

您需要使用<a>标记的ID,因此您需要更改:

    <a href='#' id="the_id"  title=....

      $("#the_id").click(); //trigger click