【问题标题】:auto click on load more but the auto click only triggers after the first manual click自动点击加载更多,但自动点击仅在第一次手动点击后触发
【发布时间】:2018-01-30 05:52:37
【问题描述】:

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

 <?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>

【问题讨论】:

    标签: javascript php jquery


    【解决方案1】:

    你需要使用&lt;a&gt;标签的id,所以你需要改一下:

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

    还有:

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

    【讨论】:

    • 能否检查条件是否正确:在点击前添加console.log,看看代码是否到达那里
    • 我已经测试了确切的代码并且它可以工作(点击 console.log),你的onlick 代码中一定有一些东西
    • 代码没有在点击时触发 console.log 我用 console.log 替换了 onclick 表达式。它没有到达那里
    • 这个jsfiddle.net/3nhwu6y7 工作正常,你能找到你的代码的不同之处吗(还要检查控制台是否有任何错误)
    • 代码没有区别。控制台显示只有手动点击才能到达代码。在滚动上什么都不做
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多